Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Nov 20, 2024
1 parent cd7caf5 commit e7063a2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 37 deletions.
2 changes: 1 addition & 1 deletion pkg/core/dao/dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestStoreAsTransaction(t *testing.T) {
stackitem.NewBool(false),
}),
ArgumentsCount: 1,
IsValid: true,
Truncated: false,
}},
},
}
Expand Down
30 changes: 16 additions & 14 deletions pkg/core/interop/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Context struct {
loadToken func(ic *Context, id int32) error
GetRandomCounter uint32
signers []transaction.Signer
SaveInvocations bool
}

// NewContext returns new interop context.
Expand All @@ -81,20 +82,21 @@ func NewContext(trigger trigger.Type, bc Ledger, d *dao.Simple, baseExecFee, bas
dao := d.GetPrivate()
cfg := bc.GetConfig().ProtocolConfiguration
return &Context{
Chain: bc,
Network: uint32(cfg.Magic),
Hardforks: cfg.Hardforks,
Natives: natives,
Trigger: trigger,
Block: block,
Tx: tx,
DAO: dao,
Log: log,
Invocations: make(map[util.Uint160]int),
getContract: getContract,
baseExecFee: baseExecFee,
baseStorageFee: baseStorageFee,
loadToken: loadTokenFunc,
Chain: bc,
Network: uint32(cfg.Magic),
Hardforks: cfg.Hardforks,
Natives: natives,
Trigger: trigger,
Block: block,
Tx: tx,
DAO: dao,
Log: log,
Invocations: make(map[util.Uint160]int),
getContract: getContract,
baseExecFee: baseExecFee,
baseStorageFee: baseStorageFee,
loadToken: loadTokenFunc,
SaveInvocations: bc.GetConfig().SaveInvocations,
}
}

Expand Down
19 changes: 9 additions & 10 deletions pkg/core/interop/contract/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,22 @@ func Call(ic *interop.Context) error {
}
hasReturn := md.ReturnType != smartcontract.VoidType

if ic.Chain.GetConfig().Ledger.SaveInvocations {
arr := stackitem.NewArray(args)
arrCount := len(args)
valid := true
argBytes := []byte{}
if argBytes, err = ic.DAO.GetItemCtx().Serialize(arr, false); err != nil {
arr = stackitem.NewArray([]stackitem.Item{})
valid = false
if ic.SaveInvocations {
var (
arrCount = len(args)
truncated = false
argBytes []byte
)
if argBytes, err = ic.DAO.GetItemCtx().Serialize(stackitem.NewArray(args), false); err != nil {
truncated = true
}

ic.InvocationCalls = append(ic.InvocationCalls, state.ContractInvocation{
Hash: u,
Method: method,
Arguments: arr,
ArgumentsBytes: argBytes,
ArgumentsCount: uint32(arrCount),
IsValid: valid,
Truncated: truncated,
})
}
return callInternal(ic, cs, method, fs, hasReturn, args, true)
Expand Down
29 changes: 17 additions & 12 deletions pkg/core/state/notification_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ type NotificationEvent struct {
Item *stackitem.Array `json:"state"`
}

// ContractInvocation contains method call information.
// The Arguments field will be nil if serialization of the arguments exceeds a predefined limit
// (for security reasons). In that case Truncated will be set to true.
type ContractInvocation struct {
Hash util.Uint160 `json:"contract_hash"`
Hash util.Uint160 `json:"contracthash"`
Method string `json:"method"`
Arguments *stackitem.Array `json:"arguments"`
ArgumentsBytes []byte `json:"arguments_bytes"`
ArgumentsCount uint32 `json:"arguments_count"`
IsValid bool `json:"is_valid"`
ArgumentsBytes []byte
ArgumentsCount uint32 `json:"argumentscount"`
Truncated bool `json:"truncated"`
}

func (ci *ContractInvocation) DecodeBinary(r *io.BinReader) {
Expand All @@ -39,15 +42,15 @@ func (ci *ContractInvocation) DecodeBinary(r *io.BinReader) {
}
ci.Arguments = si.(*stackitem.Array)
ci.ArgumentsCount = r.ReadU32LE()
ci.IsValid = r.ReadBool()
ci.Truncated = r.ReadBool()
}

func (ci *ContractInvocation) EncodeBinaryWithContext(w *io.BinWriter, sc *stackitem.SerializationContext) {
ci.Hash.EncodeBinary(w)
w.WriteString(ci.Method)
w.WriteVarBytes(ci.ArgumentsBytes)
w.WriteU32LE(ci.ArgumentsCount)
w.WriteBool(ci.IsValid)
w.WriteBool(ci.Truncated)
}

// MarshalJSON implements the json.Marshaler interface.
Expand All @@ -61,7 +64,7 @@ func (ci ContractInvocation) MarshalJSON() ([]byte, error) {
Method: ci.Method,
Arguments: item,
ArgumentsCount: ci.ArgumentsCount,
IsValid: ci.IsValid,
Truncated: ci.Truncated,
})
}

Expand All @@ -82,7 +85,7 @@ func (ci *ContractInvocation) UnmarshalJSON(data []byte) error {
ci.Method = aux.Method
ci.Hash = aux.Hash
ci.ArgumentsCount = aux.ArgumentsCount
ci.IsValid = aux.IsValid
ci.Truncated = aux.Truncated
return nil
}

Expand Down Expand Up @@ -194,7 +197,9 @@ func (aer *AppExecResult) DecodeBinary(r *io.BinReader) {
aer.Stack = arr
r.ReadArray(&aer.Events)
aer.FaultException = r.ReadString()
r.ReadArray(&aer.Invocations)
if r.Len() > 0 {
r.ReadArray(&aer.Invocations)
}
}

// notificationEventAux is an auxiliary struct for NotificationEvent JSON marshalling.
Expand Down Expand Up @@ -288,11 +293,11 @@ type Execution struct {
}

type ContractInvocationAux struct {
Hash util.Uint160 `json:"contract_hash"`
Hash util.Uint160 `json:"contracthash"`
Method string `json:"method"`
Arguments json.RawMessage `json:"arguments"`
ArgumentsCount uint32 `json:"arguments_count"`
IsValid bool `json:"is_valid"`
ArgumentsCount uint32 `json:"argumentscount"`
Truncated bool `json:"truncated"`
}

// executionAux represents an auxiliary struct for Execution JSON marshalling.
Expand Down

0 comments on commit e7063a2

Please sign in to comment.