Class: Glueby::Internal::Wallet::AbstractWalletAdapter
- Inherits:
-
Object
- Object
- Glueby::Internal::Wallet::AbstractWalletAdapter
- Defined in:
- lib/glueby/internal/wallet/abstract_wallet_adapter.rb
Overview
This is an abstract class for wallet adapters. If you want to use a wallet component with Glueby modules, you can use it by adding subclass of this abstract class for the wallet component.
Direct Known Subclasses
Instance Method Summary collapse
-
#balance(wallet_id, only_finalized = true) ⇒ Integer
Returns amount of tapyrus that the wallet has.
-
#broadcast(wallet_id, tx) { ... } ⇒ String
Broadcast the transaction to the Tapyrus Network.
-
#change_address(wallet_id) ⇒ String
Returns an address to change coin.
-
#create_pay_to_contract_address(wallet_id, contents) ⇒ String
Create and returns pay to contract address.
-
#create_pubkey(wallet_id) ⇒ Tapyrus::Key
Returns a new public key.
-
#create_wallet(wallet_id = nil) ⇒ String
Creates a new wallet inside the wallet component and returns ‘wallet_id`.
-
#delete_wallet(wallet_id) ⇒ Boolean
Delete the wallet inside the wallet component.
-
#get_addresses(wallet_id, label = nil) ⇒ Array<String>
Returns an array of addresses.
-
#get_addresses_info(addresses) ⇒ Array<Hash>
Returns information for the addresses.
-
#has_address?(wallet_id, address) ⇒ Boolean
Return if wallet has the address.
-
#list_unspent(wallet_id, only_finalized = true, label = nil, color_id: nil) ⇒ Array of UTXO
Returns the UTXOs that the wallet has.
-
#list_unspent_with_count(wallet_id, only_finalized = true, label = nil, color_id: nil, page: 1, per: 25) ⇒ Array<Utxo>
Returns all tokens with specified color_id.
-
#load_wallet(wallet_id) ⇒ Object
Load the wallet inside the wallet component.
-
#lock_unspent(wallet_id, utxo) ⇒ Object
Attempt to lock a specified utxo and update lock_at field.
-
#pay_to_contract_key(wallet_id, payment_base, contents) ⇒ Tapyrus::Key
Create pay to contract key.
-
#receive_address(wallet_id, label = nil) ⇒ String
Returns an address to receive coin.
-
#sign_to_pay_to_contract_address(wallet_id, tx, utxo, payment_base, contents, sighashtype: ) ⇒ Tapyrus::Tx
Sign to the pay to contract input.
-
#sign_tx(wallet_id, tx, prevtxs = [], sighashtype: ) ⇒ Tapyrus::Tx
Sign to the transaction with a key in the wallet.
-
#unload_wallet(wallet_id) ⇒ Boolean
Unload the wallet inside the wallet component.
-
#wallets ⇒ Array of String
Returns list of loaded wallet_id.
Instance Method Details
#balance(wallet_id, only_finalized = true) ⇒ Integer
Returns amount of tapyrus that the wallet has.
64 65 66 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 64 def balance(wallet_id, only_finalized = true) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#broadcast(wallet_id, tx) { ... } ⇒ String
Broadcast the transaction to the Tapyrus Network.
137 138 139 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 137 def broadcast(wallet_id, tx, &block) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#change_address(wallet_id) ⇒ String
Returns an address to change coin.
154 155 156 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 154 def change_address(wallet_id) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#create_pay_to_contract_address(wallet_id, contents) ⇒ String
Create and returns pay to contract address
193 194 195 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 193 def create_pay_to_contract_address(wallet_id, contents) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#create_pubkey(wallet_id) ⇒ Tapyrus::Key
Returns a new public key.
This method is expected to returns a new public key. The key would generate internally. This key is provided for contracts that need public key such as multi sig transaction.
174 175 176 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 174 def create_pubkey(wallet_id) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#create_wallet(wallet_id = nil) ⇒ String
Creates a new wallet inside the wallet component and returns ‘wallet_id`. The created wallet is loaded from at first.
13 14 15 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 13 def create_wallet(wallet_id = nil) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#delete_wallet(wallet_id) ⇒ Boolean
Delete the wallet inside the wallet component. This method expect that the wallet will be removed completely in the wallet and it cannot restore. It is assumed that the main use-case of this method is for testing.
24 25 26 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 24 def delete_wallet(wallet_id) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#get_addresses(wallet_id, label = nil) ⇒ Array<String>
Returns an array of addresses
This method is expected to return the list of addresses that wallet has.
185 186 187 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 185 def get_addresses(wallet_id, label = nil) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#get_addresses_info(addresses) ⇒ Array<Hash>
Returns information for the addresses
163 164 165 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 163 def get_addresses_info(addresses) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#has_address?(wallet_id, address) ⇒ Boolean
Return if wallet has the address
228 229 230 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 228 def has_address?(wallet_id, address) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#list_unspent(wallet_id, only_finalized = true, label = nil, color_id: nil) ⇒ Array of UTXO
Returns the UTXOs that the wallet has. If label is specified, return UTXOs filtered with label
## The UTXO structure
-
txid: [String] Transaction id
-
vout: [Integer] Output index
-
amount: [Integer] Amount of the UTXO as tapyrus unit
-
finalized: [Boolean] Whether the UTXO is finalized
-
color_id: [String] Color id of the UTXO. If it is TPC UTXO, color_id is nil.
-
script_pubkey: [String] Script pubkey of the UTXO
105 106 107 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 105 def list_unspent(wallet_id, only_finalized = true, label = nil, color_id: nil) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#list_unspent_with_count(wallet_id, only_finalized = true, label = nil, color_id: nil, page: 1, per: 25) ⇒ Array<Utxo>
Returns all tokens with specified color_id
79 80 81 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 79 def list_unspent_with_count(wallet_id, only_finalized = true, label = nil, color_id: nil, page: 1, per: 25) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#load_wallet(wallet_id) ⇒ Object
Load the wallet inside the wallet component. This method makes the wallet to possible to use on other methods like ‘balance`, `list_unspent`, etc. All the methods that gets `wallet_id` as a argument needs to load the wallet before use it. If the wallet component doesn’t need such as load operation to prepare to use the wallet, ‘load_wallet` can be empty method.
38 39 40 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 38 def load_wallet(wallet_id) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#lock_unspent(wallet_id, utxo) ⇒ Object
Attempt to lock a specified utxo and update lock_at field
113 114 115 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 113 def lock_unspent(wallet_id, utxo) true end |
#pay_to_contract_key(wallet_id, payment_base, contents) ⇒ Tapyrus::Key
Create pay to contract key
202 203 204 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 202 def pay_to_contract_key(wallet_id, payment_base, contents) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#receive_address(wallet_id, label = nil) ⇒ String
Returns an address to receive coin.
146 147 148 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 146 def receive_address(wallet_id, label = nil) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#sign_to_pay_to_contract_address(wallet_id, tx, utxo, payment_base, contents, sighashtype: ) ⇒ Tapyrus::Tx
Sign to the pay to contract input
220 221 222 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 220 def sign_to_pay_to_contract_address(wallet_id, tx, utxo, payment_base, contents, sighashtype: Tapyrus::SIGHASH_TYPE[:all]) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#sign_tx(wallet_id, tx, prevtxs = [], sighashtype: ) ⇒ Tapyrus::Tx
Sign to the transaction with a key in the wallet.
126 127 128 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 126 def sign_tx(wallet_id, tx, prevtxs = [], sighashtype: Tapyrus::SIGHASH_TYPE[:all]) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#unload_wallet(wallet_id) ⇒ Boolean
Unload the wallet inside the wallet component.
46 47 48 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 46 def unload_wallet(wallet_id) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#wallets ⇒ Array of String
Returns list of loaded wallet_id.
53 54 55 |
# File 'lib/glueby/internal/wallet/abstract_wallet_adapter.rb', line 53 def wallets raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |