Skip to content

Commit

Permalink
[action] rename execution.Contract() to To()
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinxie committed Apr 10, 2024
1 parent 1791f82 commit 66d8a51
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 17 deletions.
10 changes: 5 additions & 5 deletions action/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func NewExecutionWithAccessList(
}, nil
}

// Contract returns a contract address
func (ex *Execution) Contract() string { return ex.contract }
// To returns a contract address
func (ex *Execution) To() string { return ex.contract }

// Destination returns a contract address
func (ex *Execution) Destination() string { return ex.contract }
Expand Down Expand Up @@ -226,9 +226,9 @@ func (ex *Execution) SanityCheck() error {
return errors.Wrap(ErrInvalidAmount, "negative value")
}
// check if contract's address is valid
if ex.Contract() != EmptyAddress {
if _, err := address.FromString(ex.Contract()); err != nil {
return errors.Wrapf(err, "error when validating contract's address %s", ex.Contract())
if ex.To() != EmptyAddress {
if _, err := address.FromString(ex.To()); err != nil {
return errors.Wrapf(err, "error when validating contract's address %s", ex.To())
}
}
return ex.AbstractAction.SanityCheck()
Expand Down
8 changes: 4 additions & 4 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func newParams(
getHashFn vm.GetHashFunc
)

if dest := execution.Contract(); dest != action.EmptyAddress {
contract, err := address.FromString(execution.Contract())
if dest := execution.To(); dest != action.EmptyAddress {
contract, err := address.FromString(execution.To())
if err != nil {
return nil, errors.Wrapf(err, "failed to decode contract address %s", dest)
}
Expand Down Expand Up @@ -334,14 +334,14 @@ func ExecuteContract(

func processSGD(ctx context.Context, sm protocol.StateManager, execution *action.Execution, consumedGas uint64, sgd SGDRegistry,
) (address.Address, uint64, error) {
if execution.Contract() == action.EmptyAddress {
if execution.To() == action.EmptyAddress {
return nil, 0, nil
}
height, err := sm.Height()
if err != nil {
return nil, 0, err
}
receiver, percentage, ok, err := sgd.CheckContract(ctx, execution.Contract(), height-1)
receiver, percentage, ok, err := sgd.CheckContract(ctx, execution.To(), height-1)
if err != nil || !ok {
return nil, 0, err
}
Expand Down
2 changes: 1 addition & 1 deletion action/signedaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestSignedExecution(t *testing.T) {
require.NoError(err)

exec := selp.Action().(*Execution)
require.Equal(EmptyAddress, exec.Contract())
require.Equal(EmptyAddress, exec.To())
require.Equal(uint64(1), exec.Nonce())
require.Equal(big.NewInt(0), exec.Amount())
require.Equal(uint64(100000), exec.GasLimit())
Expand Down
2 changes: 1 addition & 1 deletion api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (core *coreService) validateChainID(chainID uint32) error {
// ReadContract reads the state in a contract address specified by the slot
func (core *coreService) ReadContract(ctx context.Context, callerAddr address.Address, sc *action.Execution) (string, *iotextypes.Receipt, error) {
log.Logger("api").Debug("receive read smart contract request")
key := hash.Hash160b(append([]byte(sc.Contract()), sc.Data()...))
key := hash.Hash160b(append([]byte(sc.To()), sc.Data()...))
// TODO: either moving readcache into the upper layer or change the storage format
if d, ok := core.readCache.Get(key); ok {
res := iotexapi.ReadContractResponse{}
Expand Down
2 changes: 1 addition & 1 deletion api/web3server_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (svr *web3Handler) assemblePendingTransaction(selp *action.SealedEnvelope)

func getRecipientAndContractAddrFromAction(selp *action.SealedEnvelope, receipt *action.Receipt) (*string, *string, error) {
// recipient is empty when contract is created
if exec, ok := selp.Action().(*action.Execution); ok && len(exec.Contract()) == 0 {
if exec, ok := selp.Action().(*action.Execution); ok && len(exec.To()) == 0 {
addr, err := ioAddrToEthAddr(receipt.ContractAddress)
if err != nil {
return nil, nil, err
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,6 @@ github.com/iotexproject/iotex-antenna-go/v2 v2.5.1/go.mod h1:8pDZcM45M0gY6jm3PoM
github.com/iotexproject/iotex-election v0.3.5-0.20210611041425-20ddf674363d h1:/j1xCAC9YiG/8UKqYvycS/v3ddVsb1G7AMyLXOjeYI0=
github.com/iotexproject/iotex-election v0.3.5-0.20210611041425-20ddf674363d/go.mod h1:GRWevxtqQ4gPMrd7Qxhr29/7aTgvjiTp+rFI9KMMZEo=
github.com/iotexproject/iotex-proto v0.5.0/go.mod h1:Xg6REkv+nTZN+OC22xXIQuqKdTWWHwOAJEXCoMpDwtI=
github.com/iotexproject/iotex-proto v0.5.15 h1:9+6szZDQ1HhSFKyB2kVlVPXdCFAHHw72VVGcYXQ7P/w=
github.com/iotexproject/iotex-proto v0.5.15/go.mod h1:wQpCk3Df0fPID+K8ohiICGj+cWRmcQ3wanT+aSrnIPo=
github.com/iotexproject/iotex-proto v0.6.0 h1:UIwPq5QuuPwR7G4OZzmyBsbvEJ+YH6oHyzRjxGk9Fow=
github.com/iotexproject/iotex-proto v0.6.0/go.mod h1:wQpCk3Df0fPID+K8ohiICGj+cWRmcQ3wanT+aSrnIPo=
github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
Expand Down
2 changes: 1 addition & 1 deletion ioctl/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func fixGasLimit(caller string, execution *action.Execution) (*action.Execution,
return nil, output.NewError(output.NetworkError,
"failed to invoke EstimateActionGasConsumption api", err)
}
return action.NewExecution(execution.Contract(), execution.Nonce(), execution.Amount(), res.Gas, execution.GasPrice(), execution.Data())
return action.NewExecution(execution.To(), execution.Nonce(), execution.Amount(), res.Gas, execution.GasPrice(), execution.Data())
}

// SendRaw sends raw action to blockchain
Expand Down
2 changes: 1 addition & 1 deletion ioctl/newcmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func fixGasLimit(client ioctl.Client, caller string, execution *action.Execution
if err != nil {
return nil, handleClientRequestError(err, "EstimateActionGasConsumption")
}
return action.NewExecution(execution.Contract(), execution.Nonce(), execution.Amount(), res.Gas, execution.GasPrice(), execution.Data())
return action.NewExecution(execution.To(), execution.Nonce(), execution.Amount(), res.Gas, execution.GasPrice(), execution.Data())
}

// SendRaw sends raw action to blockchain
Expand Down
2 changes: 1 addition & 1 deletion tools/bot/pkg/util/grpcutil/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func FixGasLimit(url string, caller string, execution *action.Execution) (exec *
if err != nil {
return
}
contract := execution.Contract()
contract := execution.To()
data := execution.Data()
return action.NewExecution(contract, execution.Nonce(), execution.Amount(), res.Gas, execution.GasPrice(), data)
}

0 comments on commit 66d8a51

Please sign in to comment.