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

Separate WS limit from HTTP message limit and set WS pong deadline timeout #405

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
151 commits
Select commit Hold shift + click to select a range
8253211
implements RLP encoding/decoding processing for structs
trinhdn2 Jun 16, 2023
fa67be8
Update RLP lib
trinhdn2 Jun 16, 2023
9b5dadb
Implement RLP encoder code generation tool
trinhdn2 Jun 16, 2023
ddf35f8
Update unit tests and benchmark
trinhdn2 Jun 16, 2023
17e4876
Include RLPgen tool to CI
trinhdn2 Jun 20, 2023
aa7c4b4
Add benchmarks for types RLP encoding/decoding
trinhdn2 Jun 21, 2023
ac89cd3
Generate RLP encoder for some structs
trinhdn2 Jun 21, 2023
060f4ce
Convert status of receipts from uint to uint64
trinhdn2 Jun 21, 2023
788eef5
cmd/tomo: added counters to the geth inspect report
endadinh Jul 13, 2023
81be749
Change handling of dirty objects in state
endadinh Jul 13, 2023
2eb2792
feat: define ExecutionResult
imterryyy98 Jul 14, 2023
a88ee1c
apply new return type
imterryyy98 Jul 14, 2023
25f4168
handle for simulate
imterryyy98 Jul 14, 2023
5e52c84
return data in json
imterryyy98 Jul 14, 2023
8843c93
Move Message struct from package types to core
trinhdn2 Jul 14, 2023
4148d3f
Calculate TRC21GasPrice when convert a transaction to a core.Message
trinhdn2 Jul 14, 2023
47b9f53
Update unit tests
trinhdn2 Jul 14, 2023
3b6e3f3
Add more information fields to transaction receipts and regen codec/RLP
trinhdn2 Jul 14, 2023
0c7da38
Add database accessor methods for receipts/logs
trinhdn2 Jul 14, 2023
e1226ec
Add chain configs as a requirement for receipts/logs retrieving
trinhdn2 Jul 14, 2023
0eb25b2
[WIP] Fix unit tests
trinhdn2 Jul 14, 2023
8fdaf68
Unify multiple keccak interface into one inside crypto package
trinhdn2 Jul 16, 2023
c7be6cc
Merge branch 'refactor/keccak-state' into ft/stacktrie
trinhdn2 Jul 16, 2023
340bf2b
Add encode method to Node interface
trinhdn2 Jul 16, 2023
33149c9
Implement stacktrie
trinhdn2 Jul 16, 2023
2e9abc4
Add encode method for rawShortNode and rawFullNode
trinhdn2 Jul 16, 2023
008274f
Fix import cycle
trinhdn2 Jul 16, 2023
f88dba4
Fix stacktrie unit tests
trinhdn2 Jul 16, 2023
af788c6
Convert status of receipts from uint to uint64
trinhdn2 Jul 16, 2023
51df1b9
Merge branch 'update/rlp-lib' into optimize/receipt-storing
trinhdn2 Jul 16, 2023
b440640
Fix unit tests
trinhdn2 Jul 16, 2023
e0f71f5
Fix unit tests
trinhdn2 Jul 16, 2023
986a3c4
Remove irrelevant code and fix unit tests
trinhdn2 Jul 17, 2023
327c90d
Remove rlpLog RLP encoder
trinhdn2 Jul 17, 2023
4d22f8d
Fix unit tests
trinhdn2 Jul 18, 2023
5f1e2b4
Minor fix after reviewing
trinhdn2 Jul 18, 2023
c37affb
Move statedb.Account struct to types.StateAccount
trinhdn2 Jul 20, 2023
e0776fb
Move database_util.go to rawdb package
trinhdn2 Jul 20, 2023
5ce901b
Move db keys to schema.go
trinhdn2 Jul 20, 2023
36373e7
Refine db keys
trinhdn2 Jul 20, 2023
6392afd
Rename
trinhdn2 Jul 20, 2023
cf62b98
Split into sub accessor files
trinhdn2 Jul 20, 2023
97a62ca
Re-enable VM tests
trinhdn2 Jul 21, 2023
024181b
chore: remove intPool
c98tristan Jul 17, 2023
c384646
Feat: Update derive SHA for stacktrie
c98tristan Jul 19, 2023
b8421e5
Chore: Add benchmark for Stacktrie
c98tristan Jul 19, 2023
6099609
Chore: Fix Update function missing return type
c98tristan Jul 19, 2023
ae6ca82
Chore: Change GetRlp to EncodeIndex in LendingTransaction and OrderTr…
c98tristan Jul 24, 2023
515a614
Update DeriveSha with new Hasher and DerivableList interface
trinhdn2 Jul 19, 2023
44d2c54
Chore: Add intPool in interpreter.go
c98tristan Jul 24, 2023
5fae822
Merge branch 'refactor/state-account' into refactor/rawdb
trinhdn2 Jul 24, 2023
72ca227
Chore: Change parameter of NewBlock function from Trie to Stacktrie
c98tristan Jul 25, 2023
530cbb1
Chore: Sorting imported library
c98tristan Jul 25, 2023
260f47e
Chore: Sorting imported library
c98tristan Jul 25, 2023
a6098a1
Merge remote-tracking branch 'c98tristan/feat/update-trie-to-stacktri…
trinhdn2 Jul 25, 2023
b1cb0fc
Resolve conflicts after merged
trinhdn2 Jul 25, 2023
5e8bde3
Refactor some rawdb methods
trinhdn2 Jul 31, 2023
cb81493
[WIP] Implement new trie interface and separate preimageStore
trinhdn2 Jul 31, 2023
a409636
Refactor NewDatabaseWithConfig
trinhdn2 Jul 31, 2023
4e70b3e
Include configs when init trie databases
trinhdn2 Jul 31, 2023
1b9882d
Nitpick
trinhdn2 Jul 31, 2023
f7bb2d3
Merge pull request #2 from trinhdn2/update/rlp-lib
trinhdn2 Jul 31, 2023
2215526
Merge branch 'develop' into refactor/message-struct
trinhdn2 Jul 31, 2023
6d8f113
Merge pull request #3 from trinhdn2/refactor/message-struct
trinhdn2 Jul 31, 2023
e29a6fe
Merge pull request #4 from trinhdn2/refactor/keccak-state
trinhdn2 Jul 31, 2023
91bc3f9
Merge branch 'develop' into optimize/receipt-storing
trinhdn2 Jul 31, 2023
4056a32
Merge pull request #5 from trinhdn2/optimize/receipt-storing
trinhdn2 Jul 31, 2023
bdec0ee
Merge branch 'develop' into ft/stacktrie
trinhdn2 Jul 31, 2023
7cb8b5e
Merge pull request #6 from trinhdn2/ft/stacktrie
trinhdn2 Jul 31, 2023
a5ca630
Merge branch 'develop' into refactor/state-account
trinhdn2 Jul 31, 2023
6a5f547
Merge pull request #7 from trinhdn2/refactor/state-account
trinhdn2 Jul 31, 2023
74ba391
Merge branch 'develop' into refactor/rawdb
trinhdn2 Aug 1, 2023
f47664c
Merge pull request #8 from trinhdn2/refactor/rawdb
trinhdn2 Aug 1, 2023
475b70a
Merge pull request #9 from c98tristan:feat/update-trie-to-stacktrie
trinhdn2 Aug 1, 2023
25f9c44
Merge branch 'develop' into feat/update-trie-to-stacktrie
trinhdn2 Aug 1, 2023
b624700
Merge pull request #9 from c98tristan/feat/update-trie-to-stacktrie
trinhdn2 Aug 1, 2023
62f26cf
Minor fix
trinhdn2 Aug 1, 2023
097326c
Bump client version to 2.4.0
trinhdn2 Aug 2, 2023
1c0d050
Merge pull request #10 from nguyenbatam/fix_api_traceblock
trinhdn2 Aug 2, 2023
943f500
Fix UpdateStorage in trie
trinhdn2 Aug 3, 2023
be70268
Fix trie unit tests
trinhdn2 Aug 3, 2023
bf41851
Fix GetCommittedState and GetState
trinhdn2 Aug 3, 2023
12d08d0
Fix state test
trinhdn2 Aug 4, 2023
fadcdab
Merge branch 'refactor/trie-interface-2' into develop
trinhdn2 Aug 4, 2023
47e5d54
Implement AddUncheckedTx in chain maker
trinhdn2 Aug 4, 2023
b4e8864
Merge branch 'optimize/receipt-storing' into develop
trinhdn2 Aug 4, 2023
40d1d00
Merge remote-tracking branch 'endale98/remove_dirty' into develop
trinhdn2 Aug 4, 2023
0d0b124
Dynamic state snapshots
endadinh Jul 14, 2023
a3c9a57
Fix after rebase
trinhdn2 Jul 17, 2023
2ad92f6
fix unit tests
endadinh Jul 17, 2023
a0d9474
Remove duplicate accessor methods
trinhdn2 Jul 17, 2023
995f139
Record prevdestruct in journal
trinhdn2 Aug 7, 2023
8d08325
Use types.SlimAccount instead of snapshot.Account
trinhdn2 Aug 7, 2023
781ac07
Rename receivers and implement pendingStorage
trinhdn2 Aug 7, 2023
d3a156f
Update statedb.go
trinhdn2 Aug 7, 2023
3659a0d
Revert
trinhdn2 Aug 10, 2023
420d343
Fix commit and copy state
trinhdn2 Aug 14, 2023
bcae7d2
Record blockWriteTimer metric
trinhdn2 Aug 18, 2023
2bacd4f
Merge pull request #13 from trinhdn2/ft/dynamic_state_snapshot
trinhdn2 Aug 18, 2023
271fdaf
Merge remote-tracking branch 'terryyyz-coin98/fix/return-revert-for-e…
trinhdn2 Aug 25, 2023
25b8733
Format code
trinhdn2 Sep 8, 2023
156f1ce
Merge pull request #16 from trinhdn2/ft/revert_errors
trinhdn2 Sep 8, 2023
35e30f6
Run gofmt and fix unit tests
Sep 20, 2023
653e72e
Add packing for dynamic array and slice types
trinhdn2 Sep 29, 2023
4e8214c
Tuple support
trinhdn2 Sep 29, 2023
a9cbf32
Add unit tests
trinhdn2 Sep 29, 2023
8dfd14b
Merge remote-tracking branch 'terryyyz-coin98/fix/return-revert-for-e…
trinhdn2 Oct 5, 2023
c746706
[WIP] Split Unpack and UnpackIntoInterface
trinhdn2 Oct 6, 2023
f545faf
Fix unpack tuple unit test
trinhdn2 Oct 8, 2023
9394238
Use UnpackIntoInterface instead of the general Unpack
trinhdn2 Oct 8, 2023
d2ac293
Parse ABI only once, create metadata struct
trinhdn2 Oct 8, 2023
80996ea
[WIP] Optimize EstimateGas API
trinhdn2 Oct 9, 2023
97284ef
Use same state for each invocation within EstimateGas
trinhdn2 Oct 10, 2023
9838222
Restore error functionality
trinhdn2 Oct 10, 2023
25bc7bc
Merge branch 'devnet' into optimize/estimate_gas
trinhdn2 Oct 10, 2023
450edd6
Merge pull request #17 from trinhdn2/optimize/estimate_gas
trinhdn2 Oct 10, 2023
6a3639b
Merge branch 'devnet' into ft/parse_ABI_once
trinhdn2 Oct 10, 2023
2a4e869
Merge pull request #18 from trinhdn2/ft/parse_ABI_once
trinhdn2 Oct 10, 2023
021856f
Fix merge conflicts
trinhdn2 Oct 10, 2023
1d81da4
Add devnet profile and reduce blocks per epoch
trinhdn2 Oct 11, 2023
a8106e2
Handle solidity panic revert
trinhdn2 Oct 26, 2023
93f0cad
Merge branch 'ft/handle_solidity_panic' into devnet
trinhdn2 Oct 26, 2023
6b84f76
Fix imports
trinhdn2 Oct 31, 2023
b0cf428
Implement IP tracker
trinhdn2 Oct 27, 2023
67a1980
Update Ethereum node record
trinhdn2 Oct 27, 2023
7c5781c
Implement new P2P node representation
trinhdn2 Oct 27, 2023
331c4d9
Port p2p/discover to p2p/enode
trinhdn2 Oct 30, 2023
47ad2d3
Port p2p to p2p/enode
trinhdn2 Oct 30, 2023
1fbef4c
Port p2p/simulations and testing to p2p/enode
trinhdn2 Oct 30, 2023
70f4faf
cmd, swarm: port to p2p/enode
trinhdn2 Oct 30, 2023
d2a975d
[WIP] Fix p2e/enode porting unit tests
trinhdn2 Oct 30, 2023
3c18913
[WIP] Fix enode unit tests
trinhdn2 Oct 31, 2023
7c3dbe0
[WIP] Fix swarm unit tests
trinhdn2 Oct 31, 2023
f562dea
Fix downloader and p2p/peer unit tests
trinhdn2 Oct 31, 2023
a73dfa8
Fix swarm upload unit test
trinhdn2 Oct 31, 2023
301300c
Implement bi-directional communication
trinhdn2 Nov 30, 2023
4ddc12c
Add HTTP timeout and cleanup
trinhdn2 Nov 30, 2023
6af9da7
Add rpc unit tests
trinhdn2 Nov 30, 2023
9fbea60
Fix protocol unit tests
trinhdn2 Dec 4, 2023
ba6b0db
Use gorilla websocket instead of native lib
trinhdn2 Dec 4, 2023
772a53b
Increase HTTP/Websocket request size limit to 5MB
trinhdn2 Dec 4, 2023
ca97f69
Update ETHstats
trinhdn2 Dec 4, 2023
89d2fce
Merge branch 'ft/p2p-enode' into ft/use_gorilla_websocket
trinhdn2 Dec 5, 2023
c3bb18b
Improve codec abstraction and use gorilla/websocket
trinhdn2 Dec 5, 2023
d7cb1cb
Use gorilla websocket in p2p/simulations
trinhdn2 Dec 5, 2023
c283f8a
Fix unit tests
trinhdn2 Dec 5, 2023
a62b058
Use gorilla websocket for cmd/faucet
trinhdn2 Dec 5, 2023
3952c1e
Send websocket ping when connection is idle
trinhdn2 Dec 5, 2023
09ad227
Re-add NewWSServer for compatibility
trinhdn2 Dec 7, 2023
94663c6
Separate and increase wsMessageSizeLimit to 32 MB
trinhdn2 Dec 7, 2023
1c3d200
Set websocket pong deadline timeout
trinhdn2 Dec 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
260 changes: 219 additions & 41 deletions accounts/abi/abi.go
Expand Up @@ -19,8 +19,13 @@ package abi
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"math/big"

"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/crypto"
)

// The ABI holds information about a contract's context and available
Expand All @@ -30,6 +35,12 @@ type ABI struct {
Constructor Method
Methods map[string]Method
Events map[string]Event

// Additional "special" functions introduced in solidity v0.6.0.
// It's separated from the original default fallback. Each contract
// can only define one fallback and receive function.
Fallback Method // Note it's also used to represent legacy fallback before v0.6.0
Receive Method
}

// JSON returns a parsed ABI interface and error if it failed.
Expand All @@ -40,7 +51,6 @@ func JSON(reader io.Reader) (ABI, error) {
if err := dec.Decode(&abi); err != nil {
return ABI{}, err
}

return abi, nil
}

Expand All @@ -58,89 +68,257 @@ func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error) {
return nil, err
}
return arguments, nil

}
method, exist := abi.Methods[name]
if !exist {
return nil, fmt.Errorf("method '%s' not found", name)
}

arguments, err := method.Inputs.Pack(args...)
if err != nil {
return nil, err
}
// Pack up the method ID too if not a constructor and return
return append(method.Id(), arguments...), nil
return append(method.ID, arguments...), nil
}

// Unpack output in v according to the abi specification
func (abi ABI) Unpack(v interface{}, name string, output []byte) (err error) {
if len(output) == 0 {
return fmt.Errorf("abi: unmarshalling empty output")
}
func (abi ABI) getArguments(name string, data []byte) (Arguments, error) {
// since there can't be naming collisions with contracts and events,
// we need to decide whether we're calling a method or an event
var args Arguments
if method, ok := abi.Methods[name]; ok {
if len(output)%32 != 0 {
return fmt.Errorf("abi: improperly formatted output")
if len(data)%32 != 0 {
return nil, fmt.Errorf("abi: improperly formatted output: %s - Bytes: [%+v]", string(data), data)
}
return method.Outputs.Unpack(v, output)
} else if event, ok := abi.Events[name]; ok {
return event.Inputs.Unpack(v, output)
args = method.Outputs
}
if event, ok := abi.Events[name]; ok {
args = event.Inputs
}
if args == nil {
return nil, errors.New("abi: could not locate named method or event")
}
return args, nil
}

// Unpack unpacks the output according to the abi specification.
func (abi ABI) Unpack(name string, data []byte) ([]interface{}, error) {
args, err := abi.getArguments(name, data)
if err != nil {
return nil, err
}
return fmt.Errorf("abi: could not locate named method or event")
return args.Unpack(data)
}

// UnmarshalJSON implements json.Unmarshaler interface
// UnpackIntoInterface unpacks the output in v according to the abi specification.
// It performs an additional copy. Please only use, if you want to unpack into a
// structure that does not strictly conform to the abi structure (e.g. has additional arguments)
func (abi ABI) UnpackIntoInterface(v interface{}, name string, data []byte) error {
args, err := abi.getArguments(name, data)
if err != nil {
return err
}
unpacked, err := args.Unpack(data)
if err != nil {
return err
}
return args.Copy(v, unpacked)
}

// UnpackIntoMap unpacks a log into the provided map[string]interface{}.
func (abi ABI) UnpackIntoMap(v map[string]interface{}, name string, data []byte) (err error) {
args, err := abi.getArguments(name, data)
if err != nil {
return err
}
return args.UnpackIntoMap(v, data)
}

// UnmarshalJSON implements json.Unmarshaler interface.
func (abi *ABI) UnmarshalJSON(data []byte) error {
var fields []struct {
Type string
Name string
Constant bool
Type string
Name string
Inputs []Argument
Outputs []Argument

// Status indicator which can be: "pure", "view",
// "nonpayable" or "payable".
StateMutability string

// Deprecated Status indicators, but removed in v0.6.0.
Constant bool // True if function is either pure or view
Payable bool // True if function is payable

// Event relevant indicator represents the event is
// declared as anonymous.
Anonymous bool
Inputs []Argument
Outputs []Argument
}

if err := json.Unmarshal(data, &fields); err != nil {
return err
}

abi.Methods = make(map[string]Method)
abi.Events = make(map[string]Event)
for _, field := range fields {
switch field.Type {
case "constructor":
abi.Constructor = Method{
Inputs: field.Inputs,
abi.Constructor = NewMethod("", "", Constructor, field.StateMutability, field.Constant, field.Payable, field.Inputs, nil)
case "function":
name := abi.overloadedMethodName(field.Name)
abi.Methods[name] = NewMethod(name, field.Name, Function, field.StateMutability, field.Constant, field.Payable, field.Inputs, field.Outputs)
case "fallback":
// New introduced function type in v0.6.0, check more detail
// here https://solidity.readthedocs.io/en/v0.6.0/contracts.html#fallback-function
if abi.HasFallback() {
return errors.New("only single fallback is allowed")
}
// empty defaults to function according to the abi spec
case "function", "":
abi.Methods[field.Name] = Method{
Name: field.Name,
Const: field.Constant,
Inputs: field.Inputs,
Outputs: field.Outputs,
abi.Fallback = NewMethod("", "", Fallback, field.StateMutability, field.Constant, field.Payable, nil, nil)
case "receive":
// New introduced function type in v0.6.0, check more detail
// here https://solidity.readthedocs.io/en/v0.6.0/contracts.html#fallback-function
if abi.HasReceive() {
return errors.New("only single receive is allowed")
}
case "event":
abi.Events[field.Name] = Event{
Name: field.Name,
Anonymous: field.Anonymous,
Inputs: field.Inputs,
if field.StateMutability != "payable" {
return errors.New("the statemutability of receive can only be payable")
}
abi.Receive = NewMethod("", "", Receive, field.StateMutability, field.Constant, field.Payable, nil, nil)
case "event":
name := abi.overloadedEventName(field.Name)
abi.Events[name] = NewEvent(name, field.Name, field.Anonymous, field.Inputs)
default:
return fmt.Errorf("abi: could not recognize type %v of field %v", field.Type, field.Name)
}
}

return nil
}

// MethodById looks up a method by the 4-byte id
// returns nil if none found
// overloadedMethodName returns the next available name for a given function.
// Needed since solidity allows for function overload.
//
// e.g. if the abi contains Methods send, send1
// overloadedMethodName would return send2 for input send.
func (abi *ABI) overloadedMethodName(rawName string) string {
name := rawName
_, ok := abi.Methods[name]
for idx := 0; ok; idx++ {
name = fmt.Sprintf("%s%d", rawName, idx)
_, ok = abi.Methods[name]
}
return name
}

// overloadedEventName returns the next available name for a given event.
// Needed since solidity allows for event overload.
//
// e.g. if the abi contains events received, received1
// overloadedEventName would return received2 for input received.
func (abi *ABI) overloadedEventName(rawName string) string {
name := rawName
_, ok := abi.Events[name]
for idx := 0; ok; idx++ {
name = fmt.Sprintf("%s%d", rawName, idx)
_, ok = abi.Events[name]
}
return name
}

// MethodById looks up a method by the 4-byte id,
// returns nil if none found.
func (abi *ABI) MethodById(sigdata []byte) (*Method, error) {
if len(sigdata) < 4 {
return nil, fmt.Errorf("data too short (%d bytes) for abi method lookup", len(sigdata))
}
for _, method := range abi.Methods {
if bytes.Equal(method.Id(), sigdata[:4]) {
if bytes.Equal(method.ID, sigdata[:4]) {
return &method, nil
}
}
return nil, fmt.Errorf("no method with id: %#x", sigdata[:4])
}

// EventByID looks an event up by its topic hash in the
// ABI and returns nil if none found.
func (abi *ABI) EventByID(topic common.Hash) (*Event, error) {
for _, event := range abi.Events {
if bytes.Equal(event.ID.Bytes(), topic.Bytes()) {
return &event, nil
}
}
return nil, fmt.Errorf("no event with id: %#x", topic.Hex())
}

// HasFallback returns an indicator whether a fallback function is included.
func (abi *ABI) HasFallback() bool {
return abi.Fallback.Type == Fallback
}

// HasReceive returns an indicator whether a receive function is included.
func (abi *ABI) HasReceive() bool {
return abi.Receive.Type == Receive
}

// revertSelector is a special function selector for revert reason unpacking.
var revertSelector = crypto.Keccak256([]byte("Error(string)"))[:4]

// panicSelector is a special function selector for panic reason unpacking.
var panicSelector = crypto.Keccak256([]byte("Panic(uint256)"))[:4]

// panicReasons map is for readable panic codes
// see this linkage for the deails
// https://docs.soliditylang.org/en/v0.8.21/control-structures.html#panic-via-assert-and-error-via-require
// the reason string list is copied from ether.js
// https://github.com/ethers-io/ethers.js/blob/fa3a883ff7c88611ce766f58bdd4b8ac90814470/src.ts/abi/interface.ts#L207-L218
var panicReasons = map[uint64]string{
0x00: "generic panic",
0x01: "assert(false)",
0x11: "arithmetic underflow or overflow",
0x12: "division or modulo by zero",
0x21: "enum overflow",
0x22: "invalid encoded storage byte array accessed",
0x31: "out-of-bounds array access; popping on an empty array",
0x32: "out-of-bounds access of an array or bytesN",
0x41: "out of memory",
0x51: "uninitialized function",
}

// UnpackRevert resolves the abi-encoded revert reason. According to the solidity
// spec https://solidity.readthedocs.io/en/latest/control-structures.html#revert,
// the provided revert reason is abi-encoded as if it were a call to function
// `Error(string)` or `Panic(uint256)`. So it's a special tool for it.
func UnpackRevert(data []byte) (string, error) {
if len(data) < 4 {
return "", errors.New("invalid data for unpacking")
}
switch {
case bytes.Equal(data[:4], revertSelector):
typ, err := NewType("string", "", nil)
if err != nil {
return "", err
}
unpacked, err := (Arguments{{Type: typ}}).Unpack(data[4:])
if err != nil {
return "", err
}
return unpacked[0].(string), nil
case bytes.Equal(data[:4], panicSelector):
typ, err := NewType("uint256", "", nil)
if err != nil {
return "", err
}
unpacked, err := (Arguments{{Type: typ}}).Unpack(data[4:])
if err != nil {
return "", err
}
pCode := unpacked[0].(*big.Int)
// uint64 safety check for future
// but the code is not bigger than MAX(uint64) now
if pCode.IsUint64() {
if reason, ok := panicReasons[pCode.Uint64()]; ok {
return reason, nil
}
}
return fmt.Sprintf("unknown panic code: %#x", pCode), nil
default:
return "", errors.New("invalid data for unpacking")
}
}