glueby 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 572e6f36cf1b1df86b93fcd264ce1a537769588a43cbe8bac5ad3d6d9df21f44
4
- data.tar.gz: 4516f08781b324f76846057cfe4722552bc413e7f9518d68b038c7bc16f03f79
3
+ metadata.gz: 8d128fa095b1dacb936a8a9ff3306b750d3cf258133f6fa469ccaf9d4d830c08
4
+ data.tar.gz: 0a0496a04b1a6b86d3f2790555ac832094cb2a809ea10262f0641520dc7cb96b
5
5
  SHA512:
6
- metadata.gz: b04613b40d622b24e14fb45440ea974905daeea6726c4a44c9e458eabe9ea552e1b8a5ad581a7ea19ab8824216f001b95c49101fdefaf2bc424a39c2fdf23d07
7
- data.tar.gz: 1e6a50bf51dd39249c5b2746e27831ca2b63da7bb02090ba2f04b978bfa172dc0372885774986cbbf94f07ccca11d82194b1d104c467d232e0916adab50c2308
6
+ metadata.gz: '07178bc49443f227073442e2d5e767e2350a1b363f72b1041b6f2feb2a6a7a413399617c97017acf73537d49e57f10d0aecb7439a8524a7c80691ccaf0620ce6'
7
+ data.tar.gz: 86d4f463995f258d3ab3496206eabc97af77f16554705f61db69c339efc146d876375cda34bf8a17425954bf51ad6c1699eb19f37676e54401c57e5026bec597
data/README.md CHANGED
@@ -183,7 +183,7 @@ In the second Fee Provider mode, the Fee Provider module pays a fee instead of t
183
183
  1. Set like below
184
184
 
185
185
  ```ruby
186
- Glurby.configure do |config|
186
+ Glueby.configure do |config|
187
187
  # Use FeeProvider to supply inputs for fees on each transaction that is created on Glueby.
188
188
  config.fee_provider_bears!
189
189
  config.fee_provider_config = {
data/glueby.gemspec CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_runtime_dependency 'tapyrus', '>= 0.2.9'
30
- spec.add_development_dependency 'activerecord'
30
+ spec.add_runtime_dependency 'activerecord'
31
31
  spec.add_development_dependency 'sqlite3'
32
32
  end
@@ -4,6 +4,7 @@ class CreateKey < ActiveRecord::Migration<%= migration_version %>
4
4
  t.string :private_key
5
5
  t.string :public_key
6
6
  t.string :script_pubkey
7
+ t.string :label, index: true
7
8
  t.integer :purpose
8
9
  t.belongs_to :wallet
9
10
  t.timestamps
@@ -5,6 +5,7 @@ class CreateUtxo < ActiveRecord::Migration<%= migration_version %>
5
5
  t.integer :index
6
6
  t.bigint :value
7
7
  t.string :script_pubkey
8
+ t.string :label, index: true
8
9
  t.integer :status
9
10
  t.belongs_to :key, null: true
10
11
  t.timestamps
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ require 'active_record'
2
3
 
3
4
  module Glueby
4
5
  module Contract
@@ -74,8 +74,8 @@ module Glueby
74
74
  wallet_adapter.balance(id, only_finalized)
75
75
  end
76
76
 
77
- def list_unspent(only_finalized = true)
78
- wallet_adapter.list_unspent(id, only_finalized)
77
+ def list_unspent(only_finalized = true, label = nil)
78
+ wallet_adapter.list_unspent(id, only_finalized, label)
79
79
  end
80
80
 
81
81
  def delete
@@ -105,8 +105,8 @@ module Glueby
105
105
  tx
106
106
  end
107
107
 
108
- def receive_address
109
- wallet_adapter.receive_address(id)
108
+ def receive_address(label = nil)
109
+ wallet_adapter.receive_address(id, label)
110
110
  end
111
111
 
112
112
  def change_address
@@ -117,8 +117,8 @@ module Glueby
117
117
  wallet_adapter.create_pubkey(id)
118
118
  end
119
119
 
120
- def collect_uncolored_outputs(amount)
121
- utxos = list_unspent
120
+ def collect_uncolored_outputs(amount, label = nil)
121
+ utxos = list_unspent(true, label)
122
122
 
123
123
  utxos.inject([0, []]) do |sum, output|
124
124
  next sum if output[:color_id]
@@ -132,8 +132,8 @@ module Glueby
132
132
  raise Glueby::Contract::Errors::InsufficientFunds
133
133
  end
134
134
 
135
- def get_addresses
136
- wallet_adapter.get_addresses(id)
135
+ def get_addresses(label = nil)
136
+ wallet_adapter.get_addresses(id, label)
137
137
  end
138
138
 
139
139
  private
@@ -65,11 +65,13 @@ module Glueby
65
65
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
66
66
  end
67
67
 
68
- # Returns all the UTXOs that the wallet has.
68
+ # Returns the UTXOs that the wallet has.
69
+ # If label is specified, return UTXOs filtered with label
69
70
  #
70
71
  # @param [String] wallet_id - The wallet id that is offered by `create_wallet()` method.
71
72
  # @param [Boolean] only_finalized - The UTXOs includes only finalized UTXO value if it
72
73
  # is true. Default is true.
74
+ # @param [String] label - Label for filtering UTXOs
73
75
  # @return [Array of UTXO]
74
76
  #
75
77
  # ## The UTXO structure
@@ -78,7 +80,7 @@ module Glueby
78
80
  # - vout: [Integer] Output index
79
81
  # - amount: [Integer] Amount of the UTXO as tapyrus unit
80
82
  # - finalized: [Boolean] Whether the UTXO is finalized
81
- def list_unspent(wallet_id, only_finalized = true)
83
+ def list_unspent(wallet_id, only_finalized = true, label = nil)
82
84
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
83
85
  end
84
86
 
@@ -107,8 +109,9 @@ module Glueby
107
109
  # Returns an address to receive coin.
108
110
  #
109
111
  # @param [String] wallet_id - The wallet id that is offered by `create_wallet()` method.
112
+ # @param [String] label The label associated with this address.
110
113
  # @return [String] P2PKH address
111
- def receive_address(wallet_id)
114
+ def receive_address(wallet_id, label = nil)
112
115
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
113
116
  end
114
117
 
@@ -136,8 +139,9 @@ module Glueby
136
139
  # This method is expected to return the list of addresses that wallet has.
137
140
  #
138
141
  # @param [String] wallet_id - The wallet id that is offered by `create_wallet()` method.
142
+ # @param [String] label The label to filter the addresses.
139
143
  # @return [Array<String>] array of P2PKH address
140
- def get_addresses(wallet_id)
144
+ def get_addresses(wallet_id, label = nil)
141
145
  raise NotImplementedError, "You must implement #{self.class}##{__method__}"
142
146
  end
143
147
  end
@@ -36,6 +36,7 @@ module Glueby
36
36
 
37
37
  utxo = Utxo.find_or_initialize_by(txid: tx.txid, index: index)
38
38
  utxo.update!(
39
+ label: key.label,
39
40
  script_pubkey: output.script_pubkey.to_hex,
40
41
  value: output.value,
41
42
  status: status,
@@ -86,10 +86,11 @@ module Glueby
86
86
  utxos.sum(&:value)
87
87
  end
88
88
 
89
- def list_unspent(wallet_id, only_finalized = true)
89
+ def list_unspent(wallet_id, only_finalized = true, label = nil)
90
90
  wallet = AR::Wallet.find_by(wallet_id: wallet_id)
91
91
  utxos = wallet.utxos
92
92
  utxos = utxos.where(status: :finalized) if only_finalized
93
+ utxos = utxos.where(label: label) if label
93
94
  utxos.map do |utxo|
94
95
  {
95
96
  txid: utxo.txid,
@@ -115,9 +116,9 @@ module Glueby
115
116
  end
116
117
  end
117
118
 
118
- def receive_address(wallet_id)
119
+ def receive_address(wallet_id, label = nil)
119
120
  wallet = AR::Wallet.find_by(wallet_id: wallet_id)
120
- key = wallet.keys.create(purpose: :receive)
121
+ key = wallet.keys.create(purpose: :receive, label: label || '')
121
122
  key.address
122
123
  end
123
124
 
@@ -133,9 +134,11 @@ module Glueby
133
134
  Tapyrus::Key.new(pubkey: key.public_key)
134
135
  end
135
136
 
136
- def get_addresses(wallet_id)
137
+ def get_addresses(wallet_id, label = nil)
137
138
  wallet = AR::Wallet.find_by(wallet_id: wallet_id)
138
- wallet.keys.map(&:address)
139
+ keys = wallet.keys
140
+ keys = keys.where(label: label) if label
141
+ keys.map(&:address)
139
142
  end
140
143
  end
141
144
  end
@@ -83,11 +83,13 @@ module Glueby
83
83
  end
84
84
  end
85
85
 
86
- def list_unspent(wallet_id, only_finalized = true)
86
+ def list_unspent(wallet_id, only_finalized = true, label = nil)
87
87
  perform_as(wallet_id) do |client|
88
88
  min_conf = only_finalized ? 1 : 0
89
89
  res = client.listunspent(min_conf)
90
90
 
91
+ res = res.filter { |i| i['label'] == label } if label
92
+
91
93
  res.map do |i|
92
94
  script = Tapyrus::Script.parse_from_payload(i['scriptPubKey'].htb)
93
95
  color_id = if script.cp2pkh? || script.cp2sh?
@@ -122,9 +124,9 @@ module Glueby
122
124
  end
123
125
  end
124
126
 
125
- def receive_address(wallet_id)
127
+ def receive_address(wallet_id, label = nil)
126
128
  perform_as(wallet_id) do |client|
127
- client.getnewaddress('', ADDRESS_TYPE)
129
+ client.getnewaddress(label || '', ADDRESS_TYPE)
128
130
  end
129
131
  end
130
132
 
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glueby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-14 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements: