github.com/iotexproject/iotex-core@v1.14.1-rc1/tools/executiontester/blockchain/array-delete-passing.go (about)

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