Class: TonSdkRubySmc::WalletV3

Inherits:
Object
  • Object
show all
Extended by:
TonSdkRuby, TonSdkRubySmc
Defined in:
lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb

Constant Summary

Constants included from TonSdkRubySmc

PWV2_CODE, SUB_WALLET_ID, TOKEN_ATTRIBUTES_SHA256, VERSION, WALLET_V3_CODE, WALLET_V4_CODE

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TonSdkRubySmc

require_type

Constructor Details

#initialize(pubkey, wc = 0, sub_wallet_id = SUB_WALLET_ID) ⇒ WalletV3

Returns a new instance of WalletV3.



67
68
69
70
71
72
73
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 67

def initialize(pubkey, wc = 0, sub_wallet_id = SUB_WALLET_ID)
  @pubkey = pubkey
  @sub_wallet_id = sub_wallet_id
  @code = deserialize(hex_to_bytes(WALLET_V3_CODE)).first
  @init = build_state_init
  @address = Address.new("#{wc}:#{init.cell.hash}")
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



65
66
67
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 65

def address
  @address
end

#codeObject

Returns the value of attribute code.



65
66
67
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 65

def code
  @code
end

#initObject

Returns the value of attribute init.



65
66
67
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 65

def init
  @init
end

#pubkeyObject

Returns the value of attribute pubkey.



65
66
67
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 65

def pubkey
  @pubkey
end

#sub_wallet_idObject

Returns the value of attribute sub_wallet_id.



65
66
67
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 65

def sub_wallet_id
  @sub_wallet_id
end

Class Method Details

.parse_storage(storage_slice) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 75

def self.parse_storage(storage_slice)
  raise 'Must be a Slice' unless storage_slice.is_a?(Slice)
  {
    seqno: storage_slice.load_uint(32),
    sub_wallet_id: storage_slice.load_uint(32),
    pubkey: storage_slice.load_bytes(32)
  }
end

Instance Method Details

#build_transfer(transfers, seqno, private_key, is_init = false, timeout = 60) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
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
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 84

def build_transfer(transfers, seqno, private_key, is_init = false, timeout = 60)
  raise 'Transfers must be an [WalletV3Transfer]' unless transfers.size > 0 && transfers.first.is_a?(WalletV3Transfer)
  raise "Wallet v3 can handle only 4 transfers at once" unless transfers.size <= 4
  body = Builder.new()
  body.store_uint(sub_wallet_id, 32)
  body.store_uint((Time.now.to_i + timeout), 32)
  body.store_uint(seqno, 32)
  transfers.each do |t|
    info = CommonMsgInfo.new(
      IntMsgInfo.new(
        tag: "int_msg_info",
        dest: t.destination,
        bounce: t.bounce,
        value: t.value,
      )
    )

    message = Message.new(
      MessageOptions.new(
        info: info,
        body: t.body,
        init: t.init,
      )
    )

    body.store_uint(t.mode, 8)
    body.store_ref(message.cell)
  end

  sign = sign_cell(body.cell, private_key)

  message_body = Builder.new
  message_body.store_bytes(sign.unpack('C*'))
  message_body.store_slice(body.cell.parse)

  info = CommonMsgInfo.new(
    ExtInMsgInfo.new(
      tag: 'ext_in_msg_info',
      dest: address
    )
  )
  init_t = is_init ? init : nil
  m_cell = message_body.cell

  message = Message.new(
    MessageOptions.new(
      info: info,
      init: init_t,
      body: m_cell
    )
  )

  message
end