Class: TonSdkRubySmc::WalletV4

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

Constant Summary collapse

WALLET_V4_CODE =
"B5EE9C72410214010002D4000114FF00F4A413F4BCF2C80B010201200203020148040504F8F28308D71820D31FD31FD31F02F823BBF264ED44D0D31FD31FD3FFF404D15143BAF2A15151BAF2A205F901541064F910F2A3F80024A4C8CB1F5240CB1F5230CBFF5210F400C9ED54F80F01D30721C0009F6C519320D74A96D307D402FB00E830E021C001E30021C002E30001C0039130E30D03A4C8CB1F12CB1FCBFF1011121302E6D001D0D3032171B0925F04E022D749C120925F04E002D31F218210706C7567BD22821064737472BDB0925F05E003FA403020FA4401C8CA07CBFFC9D0ED44D0810140D721F404305C810108F40A6FA131B3925F07E005D33FC8258210706C7567BA923830E30D03821064737472BA925F06E30D06070201200809007801FA00F40430F8276F2230500AA121BEF2E0508210706C7567831EB17080185004CB0526CF1658FA0219F400CB6917CB1F5260CB3F20C98040FB0006008A5004810108F45930ED44D0810140D720C801CF16F400C9ED540172B08E23821064737472831EB17080185005CB055003CF1623FA0213CB6ACB1FCB3FC98040FB00925F03E20201200A0B0059BD242B6F6A2684080A06B90FA0218470D4080847A4937D29910CE6903E9FF9837812801B7810148987159F31840201580C0D0011B8C97ED44D0D70B1F8003DB29DFB513420405035C87D010C00B23281F2FFF274006040423D029BE84C600201200E0F0019ADCE76A26840206B90EB85FFC00019AF1DF6A26840106B90EB858FC0006ED207FA00D4D422F90005C8CA0715CBFFC9D077748018C8CB05CB0222CF165005FA0214CB6B12CCCCC973FB00C84014810108F451F2A7020070810108D718FA00D33FC8542047810108F451F2A782106E6F746570748018C8CB05CB025006CF165004FA0214CB6A12CB1FCB3FC973FB0002006C810108D718FA00D33F305224810108F459F2A782106473747270748018C8CB05CB025005CF165003FA0213CB6ACB1F12CB3FC973FB00000AF400C9ED54696225E5"
SUB_WALLET_ID =
698983191

Constants included from TonSdkRubySmc

PWV2_CODE, TOKEN_ATTRIBUTES_SHA256, VERSION

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) ⇒ WalletV4

Returns a new instance of WalletV4.



67
68
69
70
71
72
73
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v4.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_V4_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_v4.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_v4.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_v4.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_v4.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_v4.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v4.rb', line 75

def self.parse_storage(storage_slice)
  raise "Must be a Slice" unless storage_slice.is_a?(Slice)
  deserializers = {
    key: ->(k) do
      slice = Slice.parse(Builder.new.store_bits(k).cell)
      wc = slice.load_int(8)
      addr = slice.load_bytes(32)
      Address.new("#{wc}:#{bytes_to_hex(addr)}")
    end,
    value: ->(v) { nil },
  }

  {
    seqno: storage_slice.load_uint(32),
    sub_wallet_id: storage_slice.load_uint(32),
    pubkey: storage_slice.load_bytes(32),
    plugins_list: storage_slice
      .load_dict(8 + 256, { deserializers: deserializers })
      .each { |key, value| { key: key, value: value } }
      .map { |item| item[:key] },
  }
end

Instance Method Details

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



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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v4.rb', line 98

def build_transfer(transfers, seqno, private_key, is_init = false, timeout = 60)
  raise "Transfers must be an [WalletV4Transfer]" unless transfers.size > 0 && transfers.first.is_a?(WalletV4Transfer)
  raise "Wallet v4 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)
  body.store_uint(0, 8)
  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
  body_cell = message_body.cell

  Message.new(
    MessageOptions.new(
      info: info,
      init: init_t,
      body: body_cell,
    )
  )
end