Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Synchronize contract interface naming #2801

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/native/inccounter/inccounter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestSpawn(t *testing.T) {

res, err := chain.CallView(root.Contract.Name, root.ViewGetContractRecords.Name)
require.NoError(t, err)
creg := collections.NewMapReadOnly(res, root.StateVarContractRegistry)
creg := collections.NewMapReadOnly(res, root.VarContractRegistry)
require.True(t, int(creg.Len()) == len(corecontracts.All)+2)
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/wasm/corecontracts/test/core_governance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestGetChainOwner(t *testing.T) {
f := coregovernance.ScFuncs.GetChainOwner(ctx)
f.Func.Call()
require.NoError(t, ctx.Err)
require.Equal(t, ctx.ChainOwnerID(), f.Results.ChainOwner().Value())
require.Equal(t, ctx.ChainOwnerID(), f.Results.ChainOwnerID().Value())
}

func TestGetChainNodes(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion packages/origin/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func InitChain(store state.Store, initParams dict.Dict, originDeposit uint64) st
}

evmChainID := codec.MustDecodeUint16(initParams.Get(ParamEVMChainID), evm.DefaultChainID)
blockKeepAmount := codec.MustDecodeInt32(initParams.Get(ParamBlockKeepAmount), governance.BlockKeepAmountDefault)
blockKeepAmount := codec.MustDecodeInt32(initParams.Get(ParamBlockKeepAmount), governance.DefaultBlockKeepAmount)
chainOwner := codec.MustDecodeAgentID(initParams.Get(ParamChainOwner), &isc.NilAgentID{})

// init the state of each core contract
Expand Down
2 changes: 1 addition & 1 deletion packages/solo/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (ch *Chain) GetInfo() (isc.ChainID, isc.AgentID, map[isc.Hname]*root.Contra
res, err = ch.CallView(root.Contract.Name, root.ViewGetContractRecords.Name)
require.NoError(ch.Env.T, err)

contracts, err := root.DecodeContractRegistry(collections.NewMapReadOnly(res, root.StateVarContractRegistry))
contracts, err := root.DecodeContractRegistry(collections.NewMapReadOnly(res, root.VarContractRegistry))
require.NoError(ch.Env.T, err)
return ch.ChainID, chainOwnerID, contracts
}
Expand Down
23 changes: 12 additions & 11 deletions packages/vm/core/accounts/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import (
var Contract = coreutil.NewContract(coreutil.CoreContractAccounts)

var (
// Funcs
FuncDeposit = coreutil.Func("deposit")
FuncFoundryCreateNew = coreutil.Func("foundryCreateNew")
FuncFoundryDestroy = coreutil.Func("foundryDestroy")
FuncFoundryModifySupply = coreutil.Func("foundryModifySupply")
FuncTransferAccountToChain = coreutil.Func("transferAccountToChain")
FuncTransferAllowanceTo = coreutil.Func("transferAllowanceTo")
FuncWithdraw = coreutil.Func("withdraw")
// TODO implement grant/claim protocol of moving ownership of the foundry
// Including ownership of the foundry by the common account/chain owner

// Views
ViewAccountFoundries = coreutil.ViewFunc("accountFoundries")
ViewAccountNFTAmount = coreutil.ViewFunc("accountNFTAmount")
Expand All @@ -22,19 +33,9 @@ var (
ViewGetNativeTokenIDRegistry = coreutil.ViewFunc("getNativeTokenIDRegistry")
ViewNFTData = coreutil.ViewFunc("nftData")
ViewTotalAssets = coreutil.ViewFunc("totalAssets")

// Funcs
FuncDeposit = coreutil.Func("deposit")
FuncFoundryCreateNew = coreutil.Func("foundryCreateNew")
FuncFoundryDestroy = coreutil.Func("foundryDestroy")
FuncFoundryModifySupply = coreutil.Func("foundryModifySupply")
FuncTransferAccountToChain = coreutil.Func("transferAccountToChain")
FuncTransferAllowanceTo = coreutil.Func("transferAllowanceTo")
FuncWithdraw = coreutil.Func("withdraw")
// TODO implement grant/claim protocol of moving ownership of the foundry
// Including ownership of the foundry by the common account/chain owner
)

// request parameters
const (
ParamAccountNonce = "n"
ParamAgentID = "a"
Expand Down
2 changes: 1 addition & 1 deletion packages/vm/core/accounts/nonce.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func CheckNonce(state kv.KVStoreReader, agentID isc.AgentID, nonce uint64) error
}
expected := accountNonce(state, agentID)
if nonce != expected {
return fmt.Errorf("Invalid nonce, expected %d, got %d", expected, nonce)
return fmt.Errorf("invalid nonce, expected %d, got %d", expected, nonce)
}
return nil
}
24 changes: 14 additions & 10 deletions packages/vm/core/blob/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ import (

var Contract = coreutil.NewContract(coreutil.CoreContractBlob)

const (
// request parameters
ParamHash = "hash"
ParamField = "field"
ParamBytes = "bytes"
var (
FuncStoreBlob = coreutil.Func("storeBlob")

ViewGetBlobInfo = coreutil.ViewFunc("getBlobInfo")
ViewGetBlobField = coreutil.ViewFunc("getBlobField")
ViewListBlobs = coreutil.ViewFunc("listBlobs")
)

// state variables
const (
// variable names of standard blob's field
// user-defined field must be different
VarFieldProgramBinary = "p"
VarFieldVMType = "v"
VarFieldProgramDescription = "d"
)

var (
FuncStoreBlob = coreutil.Func("storeBlob")
ViewGetBlobInfo = coreutil.ViewFunc("getBlobInfo")
ViewGetBlobField = coreutil.ViewFunc("getBlobField")
ViewListBlobs = coreutil.ViewFunc("listBlobs")
// request parameters
const (
ParamHash = "hash"
ParamField = "field"
ParamBytes = "bytes"
)

// FieldValueKey returns key of the blob field value in the SC state.
Expand Down
35 changes: 18 additions & 17 deletions packages/vm/core/blocklog/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@ import (

var Contract = coreutil.NewContract(coreutil.CoreContractBlocklog)

const (
PrefixBlockRegistry = "a"
prefixRequestLookupIndex = "b"
prefixRequestReceipts = "c"
prefixRequestEvents = "d"

// map of == request ID => unprocessableRequestRecord
prefixUnprocessableRequests = "u"
// array of request ID: list of unprocessable requests that
// need updating the outputID field
prefixNewUnprocessableRequests = "U"
)

var (
// Funcs
FuncRetryUnprocessable = coreutil.Func("retryUnprocessable")

// Views
ViewGetBlockInfo = coreutil.ViewFunc("getBlockInfo")
ViewGetRequestIDsForBlock = coreutil.ViewFunc("getRequestIDsForBlock")
ViewGetRequestReceipt = coreutil.ViewFunc("getRequestReceipt")
Expand All @@ -31,13 +22,10 @@ var (
ViewGetEventsForBlock = coreutil.ViewFunc("getEventsForBlock")
ViewGetEventsForContract = coreutil.ViewFunc("getEventsForContract")
ViewHasUnprocessable = coreutil.ViewFunc("hasUnprocessable")

// entrypoints
FuncRetryUnprocessable = coreutil.Func("retryUnprocessable")
)

// request parameters
const (
// parameters
ParamBlockIndex = "n"
ParamBlockInfo = "i"
ParamContractHname = "h"
Expand All @@ -51,3 +39,16 @@ const (
ParamStateControllerAddress = "s"
ParamUnprocessableRequestExists = "x"
)

const (
PrefixBlockRegistry = "a"
prefixRequestLookupIndex = "b"
prefixRequestReceipts = "c"
prefixRequestEvents = "d"

// map of == request ID => unprocessableRequestRecord
prefixUnprocessableRequests = "u"
// array of request ID: list of unprocessable requests that
// need updating the outputID field
prefixNewUnprocessableRequests = "U"
)
13 changes: 7 additions & 6 deletions packages/vm/core/errors/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import (

var Contract = coreutil.NewContract(coreutil.CoreContractErrors)

const (
prefixErrorTemplateMap = "a"
)

var (
FuncRegisterError = coreutil.Func("registerError")
FuncRegisterError = coreutil.Func("registerError")

ViewGetErrorMessageFormat = coreutil.ViewFunc("getErrorMessageFormat")
)

// parameters
// request parameters
const (
ParamErrorCode = "c"
ParamErrorMessageFormat = "m"
)

const (
prefixErrorTemplateMap = "a"
)
8 changes: 4 additions & 4 deletions packages/vm/core/governance/governanceimpl/chainowner.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,26 @@ func delegateChainOwnership(ctx isc.Sandbox) dict.Dict {
func setPayoutAgentID(ctx isc.Sandbox) dict.Dict {
ctx.RequireCallerIsChainOwner()
agent := ctx.Params().MustGetAgentID(governance.ParamSetPayoutAgentID)
ctx.State().Set(governance.StateVarPayoutAgentID, codec.EncodeAgentID(agent))
ctx.State().Set(governance.VarPayoutAgentID, codec.EncodeAgentID(agent))
return nil
}

func getPayoutAgentID(ctx isc.SandboxView) dict.Dict {
ret := dict.New()
ret.Set(governance.ParamSetPayoutAgentID, ctx.StateR().Get(governance.StateVarPayoutAgentID))
ret.Set(governance.ParamSetPayoutAgentID, ctx.StateR().Get(governance.VarPayoutAgentID))
return ret
}

func setMinCommonAccountBalance(ctx isc.Sandbox) dict.Dict {
ctx.RequireCallerIsChainOwner()
minCommonAccountBalance := ctx.Params().MustGetUint64(governance.ParamSetMinCommonAccountBalance)
ctx.State().Set(governance.StateVarMinBaseTokensOnCommonAccount, codec.EncodeUint64(minCommonAccountBalance))
ctx.State().Set(governance.VarMinBaseTokensOnCommonAccount, codec.EncodeUint64(minCommonAccountBalance))
return nil
}

func getMinCommonAccountBalance(ctx isc.SandboxView) dict.Dict {
return dict.Dict{
governance.ParamSetMinCommonAccountBalance: ctx.StateR().Get(governance.StateVarMinBaseTokensOnCommonAccount),
governance.ParamSetMinCommonAccountBalance: ctx.StateR().Get(governance.VarMinBaseTokensOnCommonAccount),
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/vm/core/governance/governanceimpl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ func SetInitialState(state kv.KVStore, chainOwner isc.AgentID, blockKeepAmount i
state.Set(governance.VarGasLimitsBytes, gas.LimitsDefault.Bytes())
state.Set(governance.VarMaintenanceStatus, codec.Encode(false))
state.Set(governance.VarBlockKeepAmount, codec.EncodeInt32(blockKeepAmount))
state.Set(governance.StateVarMinBaseTokensOnCommonAccount, codec.EncodeUint64(governance.DefaultMinBaseTokensOnCommonAccount))
state.Set(governance.StateVarPayoutAgentID, chainOwner.Bytes())
state.Set(governance.VarMinBaseTokensOnCommonAccount, codec.EncodeUint64(governance.DefaultMinBaseTokensOnCommonAccount))
state.Set(governance.VarPayoutAgentID, chainOwner.Bytes())
}
14 changes: 7 additions & 7 deletions packages/vm/core/governance/governanceimpl/statecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ func rotateStateController(ctx isc.Sandbox) dict.Dict {
newStateControllerAddr := ctx.Params().MustGetAddress(governance.ParamStateControllerAddress)
// check is address is allowed
state := ctx.State()
amap := collections.NewMapReadOnly(state, governance.StateVarAllowedStateControllerAddresses)
amap := collections.NewMapReadOnly(state, governance.VarAllowedStateControllerAddresses)
if !amap.HasAt(isc.AddressToBytes(newStateControllerAddr)) {
panic(vm.ErrUnauthorized)
}

if !newStateControllerAddr.Equal(ctx.StateAnchor().StateController) {
// rotate request to another address has been issued. State update will be taken over by VM and will have no effect
// By setting StateVarRotateToAddress we signal the VM this special situation
// StateVarRotateToAddress value should never persist in the state
// By setting VarRotateToAddress we signal the VM this special situation
// VarRotateToAddress value should never persist in the state
ctx.Log().Infof("Governance::RotateStateController: newStateControllerAddress=%s", newStateControllerAddr.String())
state.Set(governance.StateVarRotateToAddress, isc.AddressToBytes(newStateControllerAddr))
state.Set(governance.VarRotateToAddress, isc.AddressToBytes(newStateControllerAddr))
return nil
}
// here the new state controller address from the request equals to the state controller address in the anchor output
Expand All @@ -50,21 +50,21 @@ func rotateStateController(ctx isc.Sandbox) dict.Dict {
func addAllowedStateControllerAddress(ctx isc.Sandbox) dict.Dict {
ctx.RequireCallerIsChainOwner()
addr := ctx.Params().MustGetAddress(governance.ParamStateControllerAddress)
amap := collections.NewMap(ctx.State(), governance.StateVarAllowedStateControllerAddresses)
amap := collections.NewMap(ctx.State(), governance.VarAllowedStateControllerAddresses)
amap.SetAt(isc.AddressToBytes(addr), []byte{0x01})
return nil
}

func removeAllowedStateControllerAddress(ctx isc.Sandbox) dict.Dict {
ctx.RequireCallerIsChainOwner()
addr := ctx.Params().MustGetAddress(governance.ParamStateControllerAddress)
amap := collections.NewMap(ctx.State(), governance.StateVarAllowedStateControllerAddresses)
amap := collections.NewMap(ctx.State(), governance.VarAllowedStateControllerAddresses)
amap.DelAt(isc.AddressToBytes(addr))
return nil
}

func getAllowedStateControllerAddresses(ctx isc.SandboxView) dict.Dict {
amap := collections.NewMapReadOnly(ctx.StateR(), governance.StateVarAllowedStateControllerAddresses)
amap := collections.NewMapReadOnly(ctx.StateR(), governance.VarAllowedStateControllerAddresses)
if amap.Len() == 0 {
return nil
}
Expand Down
28 changes: 16 additions & 12 deletions packages/vm/core/governance/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var (

// gas
FuncSetFeePolicy = coreutil.Func("setFeePolicy")
ViewGetFeePolicy = coreutil.ViewFunc("getFeePolicy")
FuncSetGasLimits = coreutil.Func("setGasLimits")
ViewGetFeePolicy = coreutil.ViewFunc("getFeePolicy")
ViewGetGasLimits = coreutil.ViewFunc("getGasLimits")

// evm fees
Expand Down Expand Up @@ -58,15 +58,12 @@ var (

// state variables
const (
// DefaultMinBaseTokensOnCommonAccount can't harvest the minimum
DefaultMinBaseTokensOnCommonAccount = uint64(3000)

// state controller
StateVarAllowedStateControllerAddresses = "a"
StateVarRotateToAddress = "r"
VarAllowedStateControllerAddresses = "a"
VarRotateToAddress = "r"

StateVarPayoutAgentID = "pa"
StateVarMinBaseTokensOnCommonAccount = "vs"
VarPayoutAgentID = "pa"
VarMinBaseTokensOnCommonAccount = "vs"

// chain owner
VarChainOwnerID = "o"
Expand All @@ -93,7 +90,7 @@ const (
VarBlockKeepAmount = "b"
)

// params
// request parameters
const (
// state controller
ParamStateControllerAddress = coreutil.ParamStateControllerAddress
Expand Down Expand Up @@ -129,13 +126,20 @@ const (
ParamPublicURL = "x"

// state pruning
ParamBlockKeepAmount = "b"
BlockKeepAll = -1
BlockKeepAmountDefault = 10_000
ParamBlockKeepAmount = "b"

// set payout AgentID
ParamSetPayoutAgentID = "s"

// set min SD
ParamSetMinCommonAccountBalance = "ms"
)

// contract constants
const (
// DefaultMinBaseTokensOnCommonAccount can't harvest the minimum
DefaultMinBaseTokensOnCommonAccount = uint64(3000)

BlockKeepAll = -1
DefaultBlockKeepAmount = 10_000
)
8 changes: 4 additions & 4 deletions packages/vm/core/governance/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// If succeeds, it means this block is fake.
// If fails, return nil
func GetRotationAddress(state kv.KVStoreReader) iotago.Address {
ret, err := codec.DecodeAddress(state.Get(StateVarRotateToAddress), nil)
ret, err := codec.DecodeAddress(state.Get(VarRotateToAddress), nil)
if err != nil {
return nil
}
Expand Down Expand Up @@ -66,11 +66,11 @@ func MustGetChainInfo(state kv.KVStoreReader, chainID isc.ChainID) *isc.ChainInf
}

func MustGetMinCommonAccountBalance(state kv.KVStoreReader) uint64 {
return kvdecoder.New(state).MustGetUint64(StateVarMinBaseTokensOnCommonAccount)
return kvdecoder.New(state).MustGetUint64(VarMinBaseTokensOnCommonAccount)
}

func MustGetPayoutAgentID(state kv.KVStoreReader) isc.AgentID {
return kvdecoder.New(state).MustGetAgentID(StateVarPayoutAgentID)
return kvdecoder.New(state).MustGetAgentID(VarPayoutAgentID)
}

func mustGetChainOwnerID(state kv.KVStoreReader) isc.AgentID {
Expand Down Expand Up @@ -104,7 +104,7 @@ func GetGasLimits(state kv.KVStoreReader) (*gas.Limits, error) {
}

func GetBlockKeepAmount(state kv.KVStoreReader) int32 {
return codec.MustDecodeInt32(state.Get(VarBlockKeepAmount), BlockKeepAmountDefault)
return codec.MustDecodeInt32(state.Get(VarBlockKeepAmount), DefaultBlockKeepAmount)
}

func SetPublicURL(state kv.KVStore, url string) {
Expand Down
Loading
Loading