Class: TonSdkRubySmc::WalletV3

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

Constant Summary collapse

WALLET_V3_CODE =
"B5EE9C724101010100710000DEFF0020DD2082014C97BA218201339CBAB19F71B0ED44D0D31FD31F31D70BFFE304E0A4F2608308D71820D31FD31FD31FF82313BBF263ED44D0D31FD31FD3FFD15132BAF2A15144BAF2A204F901541055F910F2A3F8009320D74A96D307D402FB00E8D101A4C8CB1FCB1FCBFFC9ED5410BD6DAD"
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) ⇒ WalletV3

Returns a new instance of WalletV3.



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

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.



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

def address
  @address
end

#codeObject

Returns the value of attribute code.



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

def code
  @code
end

#initObject

Returns the value of attribute init.



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

def init
  @init
end

#pubkeyObject

Returns the value of attribute pubkey.



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

def pubkey
  @pubkey
end

#sub_wallet_idObject

Returns the value of attribute sub_wallet_id.



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

def sub_wallet_id
  @sub_wallet_id
end

Class Method Details

.parse_storage(storage_slice) ⇒ Object



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

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



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
# File 'lib/ton-sdk-ruby-smc/wallets/wallet_v3.rb', line 86

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(
        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(
      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