class IOSTSdk::Models::Query::Transaction

Constants

GAS_LIMIT_RANGE
GAS_RATIO_RANGE
NUMERIC_REGEX

Attributes

chain_id[RW]

Public Class Methods

attr_names() click to toggle source
# File lib/iost_sdk/models/query/transaction.rb, line 22
def self.attr_names
  [
    'time',
    'expiration',
    'gas_ratio',
    'gas_limit',
    'delay',
    'chain_id',
    'reserved',
    'signers',
    'actions',
    'amount_limit',
    'signatures'
  ]
end

Public Instance Methods

add_action(contract_id:, action_name:, action_data:) click to toggle source

Add an action to the transaction

@param contract_id [String] a Contract's ID @param action_name [String] the name of an action @param action_data [any] args to the action

# File lib/iost_sdk/models/query/transaction.rb, line 56
def add_action(contract_id:, action_name:, action_data:)
  @actions << IOSTSdk::Models::Action.new.populate(
    model_data: {
      'contract' => contract_id,
      'action_name' => action_name.to_s,
      'data' => JSON.generate(action_data)
    }
  )
end
add_approve(token:, amount:) click to toggle source

Add an amount limit to the transaction

@param token [String] name of the token @param amount [Integer|String] amount of the token or 'unlimited'

# File lib/iost_sdk/models/query/transaction.rb, line 70
def add_approve(token:, amount:)
  raise IOSTSdk::Errors::InvalidTransactionError.new('approve amount should be numeric') unless amount.is_a?(Numeric)

  @amount_limit << IOSTSdk::Models::AmountLimit.new.populate(
    model_data: {
      'token' => token.to_s,
      'value' => amount.to_s
    }
  )
end
is_valid?() click to toggle source

Verify if the transaction object is valid

# File lib/iost_sdk/models/query/transaction.rb, line 82
def is_valid?
  [
    # check gas limit
    gas_limit.is_a?(Numeric) && gas_limit.between?(GAS_LIMIT_RANGE.first, GAS_LIMIT_RANGE.last),
    # check gas ratio
    gas_ratio.is_a?(Numeric) && gas_ratio.between?(GAS_RATIO_RANGE.first, GAS_RATIO_RANGE.last),
    # check approve token and amount
    amount_limit.all? { |al| al.token != '*' || /^\d+(\.\d+)?$/ =~ al.value }
  ].all?
end
set_time_params(expiration:, delay:, server_time_diff:) click to toggle source

set the time implicitly, and set expiration and delay explicitly

@param expiration [Integer] number of seconds, since creation, the transaction will expire in @param delay [Integer] the delay @param server_time_diff [Integer] diff between client time and IOST node server time

# File lib/iost_sdk/models/query/transaction.rb, line 43
def set_time_params(expiration:, delay:, server_time_diff:)
  time_now = (Time.now.utc.to_f * 1000).to_i * 1_000_000

  @time = time_now + (server_time_diff || 0)
  @expiration = @time + expiration * 1_000_000_000
  @delay = delay
end