glueby 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14bc1f60be9eefa4527231fb46fbb0d96b7a2253b1634d94b3a8464290d2ddbb
4
- data.tar.gz: b268217f39285ae42fc2a4107bfcb5c32d9a71225e1fbb2b01296d24e62f1a1f
3
+ metadata.gz: 37c10a4359a509cd4f86c35726161717bde07bc1ce459e19b0ba4c053e8dba86
4
+ data.tar.gz: 3cd0124ed69e0f34d1adf4ff5ed26005979689befc163c970b104245f267a479
5
5
  SHA512:
6
- metadata.gz: 5a51e8f38bf391baec903a06e240294e8e75c5a881285f9be369009b77bf6fe9e8fe86fe41f43a1659344a6a38c1fcb3e2293951e8bb1a41d8beb282f63e96f6
7
- data.tar.gz: 464fb058d159a083ab096bdb077981b65069e60d1fb73d664d6ea7fb09555c2e0794f4266bb114b5d4d315910f884a3548e6dfd1cd3412c93395f3433a75eaad
6
+ metadata.gz: 68729802e9bcb1a51148c12daa1e1565180c300d43cc811c2c512056804ad2fb8cd0bd8dd0e0d915e19da2177b3a47a941a4911ce7f6376a47f598edade087fe
7
+ data.tar.gz: 902c5c0cf87cb940c9619e5f9af95367187a009ddc01d74a6604c22d8e9df9e50dec50df24455c6fb2f0a1a9020869e4d619bd879802739ba04118bf600fab6a
@@ -41,8 +41,20 @@ module Glueby
41
41
  end
42
42
  end
43
43
 
44
+ prev_txs = if funding_tx
45
+ output = funding_tx.outputs.first
46
+ [{
47
+ txid: funding_tx.txid,
48
+ vout: 0,
49
+ scriptPubKey: output.script_pubkey.to_hex,
50
+ amount: output.value
51
+ }]
52
+ else
53
+ []
54
+ end
55
+
44
56
  txb.fee(fee).change_address(wallet.internal_wallet.change_address)
45
- [funding_tx, wallet.internal_wallet.sign_tx(txb.build)]
57
+ [funding_tx, wallet.internal_wallet.sign_tx(txb.build, prev_txs)]
46
58
  end
47
59
 
48
60
  def get_transaction(tx)
@@ -72,6 +72,8 @@ module Glueby
72
72
  # @param [Boolean] only_finalized - The UTXOs includes only finalized UTXO value if it
73
73
  # is true. Default is true.
74
74
  # @param [String] label - Label for filtering UTXOs
75
+ # - If label is nil or :unlabeled, only unlabeled UTXOs will be returned.
76
+ # - If label=:all, it will return all utxos
75
77
  # @return [Array of UTXO]
76
78
  #
77
79
  # ## The UTXO structure
@@ -93,8 +93,15 @@ module Glueby
93
93
  wallet = AR::Wallet.find_by(wallet_id: wallet_id)
94
94
  utxos = wallet.utxos
95
95
  utxos = utxos.where(status: :finalized) if only_finalized
96
- utxos = utxos.where(label: label) if label && (label != :unlabeled)
97
- utxos = utxos.where(label: nil) if label == :unlabeled
96
+
97
+ if [:unlabeled, nil].include?(label)
98
+ utxos = utxos.where(label: nil)
99
+ elsif label && (label != :all)
100
+ utxos = utxos.where(label: label)
101
+ else
102
+ utxos
103
+ end
104
+
98
105
  utxos.map do |utxo|
99
106
  {
100
107
  txid: utxo.txid,
@@ -102,7 +109,8 @@ module Glueby
102
109
  script_pubkey: utxo.script_pubkey,
103
110
  color_id: utxo.color_id,
104
111
  amount: utxo.value,
105
- finalized: utxo.status == 'finalized'
112
+ finalized: utxo.status == 'finalized',
113
+ label: utxo.label
106
114
  }
107
115
  end
108
116
  end
@@ -82,14 +82,21 @@ module Glueby
82
82
  end
83
83
  end
84
84
 
85
+ # If label=nil, it will return unlabeled utxos to protect labeled utxos for specific purpose
86
+ # If label=:all, it will return all utxos
85
87
  def list_unspent(wallet_id, only_finalized = true, label = nil)
86
88
  perform_as(wallet_id) do |client|
87
89
  min_conf = only_finalized ? 1 : 0
88
90
  res = client.listunspent(min_conf)
89
91
 
90
- res = res.filter { |i| i['label'] == label } if label && (label != :unlabeled)
91
- res = res.filter { |i| i['label'] == "" } if label == :unlabeled
92
-
92
+ if [:unlabeled, nil].include?(label)
93
+ res = res.filter { |i| i['label'] == "" }
94
+ elsif label && (label != :all)
95
+ res = res.filter { |i| i['label'] == label }
96
+ else
97
+ res
98
+ end
99
+
93
100
  res.map do |i|
94
101
  script = Tapyrus::Script.parse_from_payload(i['scriptPubKey'].htb)
95
102
  color_id = if script.cp2pkh? || script.cp2sh?
@@ -101,7 +108,8 @@ module Glueby
101
108
  script_pubkey: i['scriptPubKey'],
102
109
  color_id: color_id,
103
110
  amount: tpc_to_tapyrus(i['amount']),
104
- finalized: i['confirmations'] != 0
111
+ finalized: i['confirmations'] != 0,
112
+ label: i['label']
105
113
  }
106
114
  end
107
115
  end
@@ -84,9 +84,10 @@ module Glueby
84
84
 
85
85
  # @param only_finalized [Boolean] The flag to get a UTXO with status only finalized
86
86
  # @param label [String] This label is used to filtered the UTXOs with labeled if a key or Utxo is labeled.
87
- # - If label is not specified (label=nil), all UTXOs will be returned.
88
- # - If label=:unlabeled, only unlabeled UTXOs will be returned.
89
- def list_unspent(only_finalized = true, label = nil)
87
+ # - If label is nil or :unlabeled, only unlabeled UTXOs will be returned.
88
+ # - If label=:all, all UTXOs will be returned.
89
+ def list_unspent(only_finalized = true, label = :unlabeled)
90
+ label = :unlabeled unless label
90
91
  wallet_adapter.list_unspent(id, only_finalized, label)
91
92
  end
92
93
 
@@ -1,3 +1,3 @@
1
1
  module Glueby
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.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.5.0
4
+ version: 0.5.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-11-22 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tapyrus