rename signature to selector

This commit is contained in:
Caner Çıdam 2024-02-17 00:40:42 +03:00
parent f4382a3d79
commit 45ae18fba2
2 changed files with 18 additions and 18 deletions

View File

@ -35,9 +35,9 @@ type callStack struct {
} }
type csCall struct { type csCall struct {
Op OpCode Op OpCode
Address common.Address Address common.Address
Signature []byte Selector []byte
} }
// newCallStack creates a new call stack. // newCallStack creates a new call stack.
@ -47,14 +47,14 @@ func newCallStack() *callStack {
// Push pushes given call to the stack. // Push pushes given call to the stack.
func (cs *callStack) Push(op OpCode, addr common.Address, input []byte) { func (cs *callStack) Push(op OpCode, addr common.Address, input []byte) {
var signature []byte var selector []byte
if len(input) >= 4 { if len(input) >= 4 {
signature = input[:4] selector = input[:4]
} }
cs.calls = append(cs.calls, &csCall{ cs.calls = append(cs.calls, &csCall{
Op: op, Op: op,
Address: addr, Address: addr,
Signature: signature, Selector: selector,
}) })
} }
@ -121,7 +121,7 @@ func (enc *callStackEncoder) Encode() ([]byte, error) {
for _, call := range enc.calls { for _, call := range enc.calls {
enc.appendNum(uint256.NewInt(uint64(call.Op))) enc.appendNum(uint256.NewInt(uint64(call.Op)))
enc.appendAddr(call.Address) enc.appendAddr(call.Address)
enc.appendNum(uint256.NewInt(0).SetBytes(call.Signature)) enc.appendNum(uint256.NewInt(0).SetBytes(call.Selector))
} }
return enc.result, nil return enc.result, nil

View File

@ -40,9 +40,9 @@ func benchCallStackPrecompileN(b *testing.B, n int) {
var calls []*csCall var calls []*csCall
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
calls = append(calls, &csCall{ calls = append(calls, &csCall{
Op: OpCode(i), Op: OpCode(i),
Address: common.HexToAddress("0xCdA8dcaEe60ce9d63165Ef025fD98CDA2B99B5B2"), Address: common.HexToAddress("0xCdA8dcaEe60ce9d63165Ef025fD98CDA2B99B5B2"),
Signature: []byte{0xde, 0xad, 0xbe, 0xef}, Selector: []byte{0xde, 0xad, 0xbe, 0xef},
}) })
} }
callStack := newCallStack() callStack := newCallStack()
@ -57,14 +57,14 @@ func TestCallStackPrecompile(t *testing.T) {
callStack := newCallStack() callStack := newCallStack()
callStack.calls = []*csCall{ callStack.calls = []*csCall{
{ {
Op: OpCode(0x10), Op: OpCode(0x10),
Address: common.HexToAddress("0xCdA8dcaEe60ce9d63165Ef025fD98CDA2B99B5B2"), Address: common.HexToAddress("0xCdA8dcaEe60ce9d63165Ef025fD98CDA2B99B5B2"),
Signature: []byte{0xab, 0xcd, 0xef, 0x12}, Selector: []byte{0xab, 0xcd, 0xef, 0x12},
}, },
{ {
Op: OpCode(0x20), Op: OpCode(0x20),
Address: common.HexToAddress("0xCdA8dcaEe60ce9d63165Ef025fD98CDA2B99B5B2"), Address: common.HexToAddress("0xCdA8dcaEe60ce9d63165Ef025fD98CDA2B99B5B2"),
Signature: []byte{0xde, 0xad, 0xbe, 0xef}, Selector: []byte{0xde, 0xad, 0xbe, 0xef},
}, },
} }
b, err := callStack.Run(nil) b, err := callStack.Run(nil)