Class: Keoken::Backend::Trezor::Transaction

Inherits:
Base
  • Object
show all
Defined in:
lib/keoken/backend/trezor/transaction.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#bitprim_transaction, #inputs, #tokens, #total_inputs_amount

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Keoken::Backend::Base

Instance Attribute Details

#to_jsonObject

Returns the value of attribute to_json.



7
8
9
# File 'lib/keoken/backend/trezor/transaction.rb', line 7

def to_json
  @to_json
end

Instance Method Details

#build_for_creation(address, path, script, xpubs = []) ⇒ Keoken::Backend::Trezor::Transaction

Create the transaction to broadcast in order to create tokens.

Parameters:

  • address (String)

    Address that will contain the token.

  • path (Array)

    Address derivation path.

  • script (String)

    The token script.

  • xpubs (Array) (defaults to: [])

    The xpubs corresponding to the multisig address.

Returns:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/keoken/backend/trezor/transaction.rb', line 18

def build_for_creation(address, path, script, xpubs = [])
  build_inputs([address])
  total, fee = build_fee(:create)
  output_amount = total - fee.to_i
  create(inputs: @inputs,
         path: path,
         address: address,
         output_amount: output_amount,
         script: script,
         xpubs: xpubs)
end

#build_for_empty_wallet(addresses, address_dest, path, xpubs = []) ⇒ Keoken::Backend::Trezor::Transaction

Create the transaction to broadcast in order to empty the wallet.

Parameters:

  • addresses (Array)

    Addresses that will contain the token and will be emptied.

  • address_dest (String)

    Address to receive the tokens.

  • path (Array)

    Address derivation path.

  • xpubs (Array) (defaults to: [])

    The xpubs corresponding to the multisig address.

Returns:

Raises:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/keoken/backend/trezor/transaction.rb', line 64

def build_for_empty_wallet(addresses, address_dest, path, xpubs = [])
  build_inputs(addresses)
  total, fee = build_fee(:send)
  raise Keoken::Error::NoToken if @tokens.empty?

  send(inputs: @inputs,
       path: path,
       output_amount: total - (fee.to_i * 2),
       address: nil,
       output_amount_to_addr2: fee.to_i,
       addr2: address_dest,
       script: token_script_for_inputs,
       xpubs: xpubs)
end

#build_for_send_amount(address, address_dest, path, script, xpubs = []) ⇒ Keoken::Backend::Trezor::Transaction

Create the transaction to broadcast in order to send amount between tokens.

Parameters:

  • address (String)

    Address that will contain the token.

  • address_dest (String)

    Address to receive the tokens.

  • path (Array)

    Address derivation path.

  • script (String)

    The token script.

  • xpubs (Array) (defaults to: [])

    The xpubs corresponding to the multisig address.

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/keoken/backend/trezor/transaction.rb', line 40

def build_for_send_amount(address, address_dest, path, script, xpubs = [])
  build_inputs([address])
  total, fee = build_fee(:send)
  output_amount = total - (fee.to_i * 2)
  output_amount_to_addr2 = fee.to_i
  send(inputs: @inputs,
       path: path,
       output_amount: output_amount,
       address: address,
       output_amount_to_addr2: output_amount_to_addr2,
       addr2: address_dest,
       script: script,
       xpubs: xpubs)
end