Class: Keoken::Backend::BitcoinRuby::Transaction

Inherits:
Object
  • Object
show all
Extended by:
Bitcoin::Builder
Defined in:
lib/keoken/backend/bitcoin_ruby/transaction.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#rawObject

Returns the value of attribute raw


5
6
7
# File 'lib/keoken/backend/bitcoin_ruby/transaction.rb', line 5

def raw
  @raw
end

#to_jsonObject

Returns the value of attribute to_json


5
6
7
# File 'lib/keoken/backend/bitcoin_ruby/transaction.rb', line 5

def to_json
  @to_json
end

Class Method Details

.create(tx_id, position, input_script, input_amount, output_amount, key, script) ⇒ Keoken::Backend::BitcoinRuby::Transaction

Create the transaction to broadcast in order to create tokens.

Parameters:

  • tx_id (String)

    Transaction hash.

  • position (Number)

    Transaction index of output.

  • input_script (String)

    ScriptPubKey from input.

  • input_amount (Number)

    Total amount from transaction input.

  • output_amount (Number)

    Amount to send to output, should be enough for feed.

  • key (Bitcoin::Key)

    The key obtained from Bitcoin Ruby.

  • script (String)

    The token script.

Returns:


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/keoken/backend/bitcoin_ruby/transaction.rb', line 20

def self.create(tx_id, position, input_script, input_amount, output_amount, key, script)
  token = new
  tx = build_tx do |t|
    t.input do |i|
      i.prev_out(tx_id, position, input_script.htb, input_amount, 0)
      i.signature_key(key)
    end
    t.output do |o|
      o.value output_amount
      o.script do |s|
        s.recipient(key.addr)
      end
    end
    t.output do |o|
      o.value 0
      o.to(script, :custom)
    end
  end
  token.to_json = tx.to_json
  token.raw = tx.to_payload.bth
  token
end

.send_amount(tx_id, position, input_script, input_amount, output_amount, output_amount_to_addr2, addr2, key, script) ⇒ Keoken::Backend::BitcoinRuby::Transaction

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

Parameters:

  • tx_id (String)

    Transaction hash.

  • position (Number)

    Transaction index of output.

  • input_script (String)

    ScriptPubKey from input.

  • input_amount (Number)

    Total amount from transaction input.

  • output_amount (Number)

    Amount to send to output, should be enough for feed.

  • output_amount_to_addr2 (Number)

    Amount to send to the output address to receive the tokens, should be low enough for feed.

  • addr2 (String)

    Address to receive the tokens.

  • key (Bitcoin::Key)

    The key obtained from Bitcoin Ruby.

  • script (String)

    The token script.

Returns:


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/keoken/backend/bitcoin_ruby/transaction.rb', line 57

def self.send_amount(tx_id, position, input_script, input_amount, output_amount, output_amount_to_addr2, addr2, key, script)
  token = self.new
  tx = build_tx do |t|
    t.input do |i|
      i.prev_out(tx_id, position, input_script.htb, input_amount, 0)
      i.signature_key(key)
    end
    t.output do |o|
      o.value output_amount_to_addr2
      o.script do |s|
        s.recipient(addr2)
      end
    end
    t.output do |o|
      o.value output_amount
      o.script do |s|
        s.recipient(key.addr)
      end
    end
    t.output do |o|
      o.value 0
      o.to(script, :custom)
    end
  end
  token.to_json = tx.to_json
  token.raw = tx.to_payload.bth
  token
end