Class: TonSdkRubySmc::PWV2

Inherits:
Object
  • Object
show all
Defined in:
lib/ton-sdk-ruby-smc/wallets/pwv2.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pubkey, wc = 0) ⇒ PWV2

Returns a new instance of PWV2.



63
64
65
66
67
68
# File 'lib/ton-sdk-ruby-smc/wallets/pwv2.rb', line 63

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

Instance Attribute Details

#addressObject

Returns the value of attribute address.



61
62
63
# File 'lib/ton-sdk-ruby-smc/wallets/pwv2.rb', line 61

def address
  @address
end

#codeObject

Returns the value of attribute code.



61
62
63
# File 'lib/ton-sdk-ruby-smc/wallets/pwv2.rb', line 61

def code
  @code
end

#initObject

Returns the value of attribute init.



61
62
63
# File 'lib/ton-sdk-ruby-smc/wallets/pwv2.rb', line 61

def init
  @init
end

#pubkeyObject

Returns the value of attribute pubkey.



61
62
63
# File 'lib/ton-sdk-ruby-smc/wallets/pwv2.rb', line 61

def pubkey
  @pubkey
end

Class Method Details

.parse_storage(storage_slice) ⇒ Object



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

def self.parse_storage(storage_slice)
  {
    pubkey: storage_slice.load_bytes(32),
    seqno: storage_slice.load_uint(16)
  }
end

Instance Method Details

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



77
78
79
80
81
82
83
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
138
139
140
141
# File 'lib/ton-sdk-ruby-smc/wallets/pwv2.rb', line 77

def build_transfer(transfers, seqno, private_key, is_init = false, timeout = 60)
  raise 'Transfers must be an [PWV2Transfer]' unless transfers.size > 0 && transfers.first.is_a?(PWV2Transfer)
  raise "PWV2 can handle only 255 transfers at once" unless transfers.size <= 255
  actions = []

  transfers.each do |t|
    info = CommonMsgInfo.new(
      IntMsgInfo.new(
        tag: 'int_msg_info',
        dest: t.destination,
        bounce: t.bounce,
        value: t.value
      )
    )

    action = OutAction.new(
      ActionSendMsg.new(
        tag: 'action_send_msg',
        mode: t.mode,
        out_msg: Message.new(
          MessageOptions.new(
            info: info,
            body: t.body,
            init: t.init
          )
        )
      )
    )

    actions.push(action)
  end

  outlist = OutList.new(OutListOptions.new(actions: actions))

  msg_inner = Builder.new
    .store_uint((Time.now.to_i + timeout).to_s, 64)
    .store_uint(seqno.to_s, 16)
    .store_ref(outlist.cell)
    .cell

  sign = sign_cell(msg_inner, private_key)

  msg_body = Builder.new
    .store_bytes(sign.unpack('C*'))
    .store_ref(msg_inner)

  info = CommonMsgInfo.new(
    ExtInMsgInfo.new(
      tag: 'ext_in_msg_info',
      dest: @address
    )
  )

  init_t = is_init ? init : nil

  m_cell = msg_body.cell

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