/
array-delete-passing.go
54 lines (47 loc) · 1.52 KB
/
array-delete-passing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2019 IoTeX Foundation
// This source code is provided 'as is' and no warranties are given as to title or non-infringement, merchantability
// or fitness for purpose and, to the extent permitted by law, all liability for your use of the code is disclaimed.
// This source code is governed by Apache License 2.0 that can be found in the LICENSE file.
package blockchain
import (
"encoding/hex"
"math/big"
)
type (
// ArrayDeletePassing interface for array-delete.sol
ArrayDeletePassing interface {
Contract
GetArray() (ret []*big.Int, err error)
GetNum() (ret int64, err error)
}
arrayDeletePassing struct {
Contract
}
)
// NewArrayDelete creates a new ArrayDelete contract
func NewArrayDelete(exp string) ArrayDeletePassing {
return &arrayDeletePassing{Contract: NewContract(exp)}
}
// MainFunc is function main() returns (uint[])
func (f *arrayDeletePassing) GetArray() (ret []*big.Int, err error) {
retString, err := f.RunAsOwner().SetAddress(f.Address()).Read(ArrayDeletePassingGetArray, []byte(Producer))
if err != nil {
return
}
retBytes, err := hex.DecodeString(retString)
if err != nil {
return
}
len := len(retBytes) / 32
for i := 2; i < len; i++ {
b := retBytes[i*32 : (i+1)*32]
retBig := new(big.Int).SetBytes(b)
ret = append(ret, retBig)
}
return
}
// GetNum is calling function makeA() returns (uint256)
func (f *arrayDeletePassing) GetNum() (ret int64, err error) {
ret, err = f.RunAsOwner().SetAddress(f.Address()).ReadValue(f.Address(), ArrayDeletePassingMakeA, Producer)
return
}