Class: IOSTSdk::Main
Constant Summary collapse
- DEFAULTS =
{ gas_limit: 2_000_000, gas_ratio: 1, delay: 0, expiration: 90, approval_limit_amount: :unlimited }.freeze
Instance Attribute Summary collapse
-
#approval_limit_amount ⇒ Object
Returns the value of attribute approval_limit_amount.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#delay ⇒ Object
Returns the value of attribute delay.
-
#expiration ⇒ Object
Returns the value of attribute expiration.
-
#gas_limit ⇒ Object
Returns the value of attribute gas_limit.
-
#gas_ratio ⇒ Object
Returns the value of attribute gas_ratio.
-
#transaction ⇒ Object
Returns the value of attribute transaction.
Instance Method Summary collapse
-
#call_abi(contract_id:, abi_name:, abi_args:) ⇒ Object
Create an instance of IOSTSdk::Models::Transaction with an action to call the ABI.
-
#initialize(endpoint:) ⇒ Main
constructor
A new instance of Main.
-
#new_account(name:, creator:, owner_key:, active_key:, initial_ram:, initial_gas_pledge:) ⇒ Object
Create an instance IOSTSdk::Models::Transaction to create a new account.
- #sign_and_send(account_name:, key_pair:) ⇒ Object
-
#transfer(token:, from:, to:, amount:, memo:) ⇒ Object
Create an instance IOSTSdk::Models::Transaction with an action to transfer tokens.
Constructor Details
Instance Attribute Details
#approval_limit_amount ⇒ Object
Returns the value of attribute approval_limit_amount.
16 17 18 |
# File 'lib/iost_sdk.rb', line 16 def approval_limit_amount @approval_limit_amount end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/iost_sdk.rb', line 15 def client @client end |
#delay ⇒ Object
Returns the value of attribute delay.
16 17 18 |
# File 'lib/iost_sdk.rb', line 16 def delay @delay end |
#expiration ⇒ Object
Returns the value of attribute expiration.
16 17 18 |
# File 'lib/iost_sdk.rb', line 16 def expiration @expiration end |
#gas_limit ⇒ Object
Returns the value of attribute gas_limit.
16 17 18 |
# File 'lib/iost_sdk.rb', line 16 def gas_limit @gas_limit end |
#gas_ratio ⇒ Object
Returns the value of attribute gas_ratio.
16 17 18 |
# File 'lib/iost_sdk.rb', line 16 def gas_ratio @gas_ratio end |
#transaction ⇒ Object
Returns the value of attribute transaction.
16 17 18 |
# File 'lib/iost_sdk.rb', line 16 def transaction @transaction end |
Instance Method Details
#call_abi(contract_id:, abi_name:, abi_args:) ⇒ Object
Create an instance of IOSTSdk::Models::Transaction with an action to call the ABI.
57 58 59 60 61 62 63 64 65 |
# File 'lib/iost_sdk.rb', line 57 def call_abi(contract_id:, abi_name:, abi_args:) transaction = init_transaction transaction.add_action(contract_id: contract_id, action_name: abi_name, action_data: abi_args) transaction.add_approve(token: '*', amount: :unlimited) transaction.set_time_params(expiration: expiration, delay: delay) @transaction = transaction self end |
#new_account(name:, creator:, owner_key:, active_key:, initial_ram:, initial_gas_pledge:) ⇒ Object
Create an instance IOSTSdk::Models::Transaction to create a new account
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/iost_sdk.rb', line 95 def new_account(name:, creator:, owner_key:, active_key:, initial_ram:, initial_gas_pledge:) transaction = init_transaction transaction.add_action( contract_id: 'auth.iost', action_name: :signUp, action_data: [name, owner_key.id, active_key.id] ) if initial_ram > 10 transaction.add_action( contract_id: 'ram.iost', action_name: :buy, action_data: [creator, name, initial_ram] ) end if initial_gas_pledge > 0 transaction.add_action( contract_id: 'ram.iost', action_name: :buy, action_data: [creator, name, initial_gas_pledge.to_s] ) end transaction.set_time_params(expiration: expiration, delay: delay) transaction.add_approve(token: '*', amount: approval_limit_amount) @transaction = transaction self end |
#sign_and_send(account_name:, key_pair:) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/iost_sdk.rb', line 41 def sign_and_send(account_name:, key_pair:) if @transaction @client.send_tx( transaction: @transaction, account_name: account_name, key_pair: key_pair ) end end |
#transfer(token:, from:, to:, amount:, memo:) ⇒ Object
Create an instance IOSTSdk::Models::Transaction with an action to transfer tokens
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/iost_sdk.rb', line 75 def transfer(token:, from:, to:, amount:, memo:) call_abi( contract_id: 'token.iost', abi_name: :transfer, abi_args: [token, from, to, amount, memo] ) @transaction.add_approve(token: :iost, amount: amount) @transaction.set_time_params(expiration: expiration, delay: delay) self end |