Class: TezosClient
- Inherits:
-
Object
- Object
- TezosClient
- Defined in:
- lib/tezos_client.rb,
lib/tezos_client/crypto.rb,
lib/tezos_client/logger.rb,
lib/tezos_client/version.rb,
lib/tezos_client/commands.rb,
lib/tezos_client/operation.rb,
lib/tezos_client/encode_utils.rb,
lib/tezos_client/string_utils.rb,
lib/tezos_client/rpc_interface.rb,
lib/tezos_client/currency_utils.rb,
lib/tezos_client/client_interface.rb,
lib/tezos_client/liquidity_interface.rb,
lib/tezos_client/client_interface/key.rb,
lib/tezos_client/rpc_interface/blocks.rb,
lib/tezos_client/rpc_interface/helper.rb,
lib/tezos_client/client_interface/misc.rb,
lib/tezos_client/rpc_interface/context.rb,
lib/tezos_client/rpc_interface/monitor.rb,
lib/tezos_client/rpc_interface/contracts.rb,
lib/tezos_client/client_interface/contract.rb,
lib/tezos_client/operations/reveal_operation.rb,
lib/tezos_client/rpc_interface/request_manager.rb,
lib/tezos_client/client_interface/client_wrapper.rb,
lib/tezos_client/operations/origination_operation.rb,
lib/tezos_client/operations/transaction_operation.rb,
lib/tezos_client/client_interface/block_contextual.rb,
lib/tezos_client/operations/transactions_operation.rb,
lib/tezos_client/liquidity_inteface/liquidity_wrapper.rb,
lib/tezos_client/operations/activate_account_operation.rb
Defined Under Namespace
Modules: Commands, Crypto, CurrencyUtils, EncodeUtils, Logger, StringUtils Classes: ActivateAccountOperation, ClientInterface, LiquidityInterface, Operation, OriginationOperation, RevealOperation, RpcInterface, TransactionOperation, TransactionsOperation
Constant Summary collapse
- RANDOM_SIGNATURE =
"edsigu165B7VFf3Dpw2QABVzEtCxJY2gsNBNcE3Ti7rRxtDUjqTFRpg67EdAQmY6YWPE5tKJDMnSTJDFu65gic8uLjbW2YwGvAZ"- VERSION =
"0.3.9"
Constants included from Crypto
Crypto::PREFIXES, Crypto::WATERMARK
Instance Attribute Summary collapse
-
#client_interface ⇒ Object
Returns the value of attribute client_interface.
-
#liquidity_interface ⇒ Object
Returns the value of attribute liquidity_interface.
-
#rpc_interface ⇒ Object
Returns the value of attribute rpc_interface.
Instance Method Summary collapse
- #activate_account(pkh:, secret:, **args) ⇒ Object
- #block_include_operation?(operation_id, block_id) ⇒ Boolean
- #call_contract(args) ⇒ Object
-
#initialize(rpc_node_address: "127.0.0.1", rpc_node_port: 8732) ⇒ TezosClient
constructor
A new instance of TezosClient.
- #monitor_operation(operation_id, timeout: 120) ⇒ Object
-
#originate_contract(from:, amount:, secret_key:, **args) ⇒ Hash
Originates a contract on the tezos blockchain.
- #reveal_pubkey(secret_key:, **args) ⇒ Object
-
#transfer(from:, amount:, to:, secret_key:, **args) ⇒ Hash
Transfer funds to an account.
- #transfer_to_many(from:, amounts:, secret_key:, **args) ⇒ Object
Methods included from Crypto
#checksum, #decode_account_wallet, #decode_base58, #decode_tz, #encode_base58, #encode_tz, #generate_key, #generate_mnemonic, #get_prefix_and_payload, #hex_prefix, #operation_id, #public_key_to_address, #secret_key_to_public_key, #sign_bytes, #sign_operation, #signing_key
Methods included from Logger
Constructor Details
#initialize(rpc_node_address: "127.0.0.1", rpc_node_port: 8732) ⇒ TezosClient
Returns a new instance of TezosClient.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tezos_client.rb', line 42 def initialize(rpc_node_address: "127.0.0.1", rpc_node_port: 8732) @rpc_node_address = rpc_node_address @rpc_node_port = rpc_node_port @client_config_file = ENV["TEZOS_CLIENT_CONFIG_FILE"] @client_interface = ClientInterface.new( config_file: @client_config_file ) @rpc_interface = RpcInterface.new( host: @rpc_node_address, port: @rpc_node_port ) @liquidity_interface = LiquidityInterface.new( rpc_node_address: @rpc_node_address, rpc_node_port: @rpc_node_port ) end |
Instance Attribute Details
#client_interface ⇒ Object
Returns the value of attribute client_interface.
36 37 38 |
# File 'lib/tezos_client.rb', line 36 def client_interface @client_interface end |
#liquidity_interface ⇒ Object
Returns the value of attribute liquidity_interface.
38 39 40 |
# File 'lib/tezos_client.rb', line 38 def liquidity_interface @liquidity_interface end |
#rpc_interface ⇒ Object
Returns the value of attribute rpc_interface.
37 38 39 |
# File 'lib/tezos_client.rb', line 37 def rpc_interface @rpc_interface end |
Instance Method Details
#activate_account(pkh:, secret:, **args) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'lib/tezos_client.rb', line 110 def activate_account(pkh:, secret:, **args) ActivateAccountOperation.new( liquidity_interface: liquidity_interface, rpc_interface: rpc_interface, pkh: pkh, secret: secret, **args ).test_and_broadcast end |
#block_include_operation?(operation_id, block_id) ⇒ Boolean
191 192 193 194 |
# File 'lib/tezos_client.rb', line 191 def block_include_operation?(operation_id, block_id) operations = rpc_interface.get("chains/main/blocks/#{block_id}/operation_hashes") operations.flatten.include? operation_id end |
#call_contract(args) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/tezos_client.rb', line 146 def call_contract(args) parameters = args.fetch(:parameters) json_params = liquidity_interface.call_parameters( script: args.fetch(:script), parameters: parameters ) transfer_args = args.merge(parameters: json_params) transfer(transfer_args) end |
#monitor_operation(operation_id, timeout: 120) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/tezos_client.rb', line 159 def monitor_operation(operation_id, timeout: 120) including_block = nil monitoring_thread = rpc_interface.monitor_block do |block_header| log "recently received block: #{block_header.pretty_inspect}" hash = block_header["hash"] if block_include_operation?(operation_id, hash) log "operations #{operation_id} found in block #{hash}" including_block = hash end end Timeout.timeout(timeout) do loop do sleep(0.1) break unless monitoring_thread.alive? break unless including_block.nil? end end if monitoring_thread.status.nil? # when thread raise an Exception, reraise it log "monitoring thread raised an exception" monitoring_thread.value else monitoring_thread.terminate end including_block end |
#originate_contract(from:, amount:, secret_key:, **args) ⇒ Hash
Originates a contract on the tezos blockchain
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/tezos_client.rb', line 75 def originate_contract(from:, amount:, secret_key:, **args) res = OriginationOperation.new( liquidity_interface: liquidity_interface, rpc_interface: rpc_interface, from: from, secret_key: secret_key, amount: amount, **args ).test_and_broadcast res.merge(originated_contract: res[:operation_result][:originated_contracts][0]) end |
#reveal_pubkey(secret_key:, **args) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/tezos_client.rb', line 131 def reveal_pubkey(secret_key:, **args) public_key = secret_key_to_public_key(secret_key) from = public_key_to_address(public_key) RevealOperation.new( liquidity_interface: liquidity_interface, rpc_interface: rpc_interface, public_key: public_key, from: from, secret_key: secret_key, **args ).test_and_broadcast end |
#transfer(from:, amount:, to:, secret_key:, **args) ⇒ Hash
Transfer funds to an account
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/tezos_client.rb', line 98 def transfer(from:, amount:, to:, secret_key:, **args) TransactionOperation.new( liquidity_interface: liquidity_interface, rpc_interface: rpc_interface, from: from, to: to, secret_key: secret_key, amount: amount, **args ).test_and_broadcast end |
#transfer_to_many(from:, amounts:, secret_key:, **args) ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/tezos_client.rb', line 120 def transfer_to_many(from:, amounts:, secret_key:, **args) TransactionsOperation.new( liquidity_interface: liquidity_interface, rpc_interface: rpc_interface, from: from, amounts: amounts, secret_key: secret_key, **args ).test_and_broadcast end |