-
Notifications
You must be signed in to change notification settings - Fork 80
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
*: add invocations to applicationlog #3569
Open
ixje
wants to merge
6
commits into
nspcc-dev:master
Choose a base branch
from
ixje:applog-invocations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+235
−24
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d8a0d13
Store invocations in application log
ixje 04c71f5
rename params to arguments
ixje dfd5c9b
make invocation saving configurable, safely handle args
ixje cd7caf5
re-use serialized arguments for storing
ixje e7063a2
feedback
ixje ae3b481
process feedback
ixje File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package state | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/nspcc-dev/neo-go/pkg/io" | ||
"github.com/nspcc-dev/neo-go/pkg/util" | ||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem" | ||
) | ||
|
||
// NewContractInvocation return a new ContractInvocation. | ||
func NewContractInvocation(hash util.Uint160, method string, argBytes []byte, argCnt uint32, truncated bool) *ContractInvocation { | ||
return &ContractInvocation{ | ||
Hash: hash, | ||
Method: method, | ||
argumentsBytes: argBytes, | ||
ArgumentsCount: argCnt, | ||
Truncated: truncated, | ||
} | ||
} | ||
|
||
// ContractInvocation contains method call information. | ||
// The Arguments field will be nil if serialization of the arguments exceeds the predefined limit | ||
// of [stackitem.MaxSerialized] (for security reasons). In that case Truncated will be set to true. | ||
type ContractInvocation struct { | ||
Hash util.Uint160 `json:"contract"` | ||
Method string `json:"method"` | ||
// Arguments are the arguments as passed to the `args` parameter of System.Contract.Call | ||
// for use in the RPC Server and RPC Client. | ||
Arguments *stackitem.Array `json:"arguments"` | ||
// argumentsBytes is the serialized arguments used at the interop level. | ||
argumentsBytes []byte | ||
ArgumentsCount uint32 `json:"argumentscount"` | ||
Truncated bool `json:"truncated"` | ||
} | ||
|
||
// DecodeBinary implements the Serializable interface. | ||
func (ci *ContractInvocation) DecodeBinary(r *io.BinReader) { | ||
ci.Hash.DecodeBinary(r) | ||
ci.Method = r.ReadString() | ||
ci.argumentsBytes = r.ReadVarBytes() | ||
ci.ArgumentsCount = r.ReadU32LE() | ||
ci.Truncated = r.ReadBool() | ||
} | ||
|
||
// EncodeBinary implements the Serializable interface. | ||
func (ci *ContractInvocation) EncodeBinary(w *io.BinWriter) { | ||
ci.EncodeBinaryWithContext(w, stackitem.NewSerializationContext()) | ||
} | ||
|
||
// EncodeBinaryWithContext is the same as EncodeBinary, but allows to efficiently reuse | ||
// stack item serialization context. | ||
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.Truncated) | ||
} | ||
|
||
// MarshalJSON implements the json.Marshaler interface. | ||
func (ci ContractInvocation) MarshalJSON() ([]byte, error) { | ||
si, err := stackitem.Deserialize(ci.argumentsBytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
item, err := stackitem.ToJSONWithTypes(si.(*stackitem.Array)) | ||
if err != nil { | ||
item = []byte(fmt.Sprintf(`"error: %v"`, err)) | ||
} | ||
return json.Marshal(contractInvocationAux{ | ||
Hash: ci.Hash, | ||
Method: ci.Method, | ||
Arguments: item, | ||
ArgumentsCount: ci.ArgumentsCount, | ||
Truncated: ci.Truncated, | ||
}) | ||
} | ||
|
||
// UnmarshalJSON implements the json.Unmarshaler interface. | ||
func (ci *ContractInvocation) UnmarshalJSON(data []byte) error { | ||
aux := new(contractInvocationAux) | ||
if err := json.Unmarshal(data, aux); err != nil { | ||
return err | ||
} | ||
params, err := stackitem.FromJSONWithTypes(aux.Arguments) | ||
if err != nil { | ||
return err | ||
} | ||
if t := params.Type(); t != stackitem.ArrayT { | ||
return fmt.Errorf("failed to convert invocation state of type %s to array", t.String()) | ||
} | ||
ci.Arguments = params.(*stackitem.Array) | ||
ci.Method = aux.Method | ||
ci.Hash = aux.Hash | ||
ci.ArgumentsCount = aux.ArgumentsCount | ||
ci.Truncated = aux.Truncated | ||
return nil | ||
} | ||
|
||
// contractInvocationAux is an auxiliary struct for ContractInvocation JSON marshalling. | ||
type contractInvocationAux struct { | ||
Hash util.Uint160 `json:"hash"` | ||
Method string `json:"method"` | ||
Arguments json.RawMessage `json:"arguments"` | ||
ArgumentsCount uint32 `json:"argumentscount"` | ||
Truncated bool `json:"truncated"` | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, adjust
docs/node-configuration.md
. Write some details on how this feature works and recommendations on situations when it should be enabled/disabled.