forked from iotexproject/iotex-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
array-of-strings.go
46 lines (39 loc) · 1.28 KB
/
array-of-strings.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
// Copyright (c) 2019 IoTeX
// This is an alpha (internal) release and is not suitable for production. 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 (
// ArrayString interface for array-of-strings.sol
ArrayString interface {
Contract
GetString() (ret string, err error)
}
arrayString struct {
Contract
}
)
// NewArrayString creates a new ArrayString contract
func NewArrayString(exp string) ArrayString {
return &arrayString{Contract: NewContract(exp)}
}
// GetString is calling function bar() constant returns(string)
func (f *arrayString) GetString() (ret string, err error) {
rets, err := f.RunAsOwner().SetAddress(f.Address()).Read(ArrayStringBar, []byte(Producer))
retBytes, err := hex.DecodeString(rets)
if err != nil {
return
}
len := len(retBytes) / 32
lenOfString := new(big.Int).SetBytes(retBytes[1*32 : (1+1)*32])
for i := 2; i < len; i++ {
b := retBytes[i*32 : (i+1)*32]
ret += string(b[:lenOfString.Uint64()])
}
return
}