Skip to content

Commit 055b92b

Browse files
committed
Fixes after merge
1 parent b115388 commit 055b92b

File tree

3 files changed

+9
-238
lines changed

3 files changed

+9
-238
lines changed

accounts/abi/argument.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -241,41 +241,7 @@ func (arguments Arguments) UnpackValues(data []byte) ([]any, error) {
241241
return retval, nil
242242
}
243243

244-
// UnpackValues can be used to unpack ABI-encoded hexdata according to the ABI-specification,
245-
// without supplying a struct to unpack into. Instead, this method returns a list containing the
246-
// values converted to strings. An atomic argument will be a list with one element.
247-
func (arguments Arguments) UnpackValuesAsStrings(data []byte) ([]interface{}, error) {
248-
nonIndexedArgs := arguments.NonIndexed()
249-
retval := make([]interface{}, 0, len(nonIndexedArgs))
250-
virtualArgs := 0
251-
for index, arg := range nonIndexedArgs {
252-
marshalledValue, err := toString((index+virtualArgs)*32, arg.Type, data)
253-
if err != nil {
254-
return nil, err
255-
}
256-
if arg.Type.T == ArrayTy && !isDynamicType(arg.Type) {
257-
// If we have a static array, like [3]uint256, these are coded as
258-
// just like uint256,uint256,uint256.
259-
// This means that we need to add two 'virtual' arguments when
260-
// we count the index from now on.
261-
//
262-
// Array values nested multiple levels deep are also encoded inline:
263-
// [2][3]uint256: uint256,uint256,uint256,uint256,uint256,uint256
264-
//
265-
// Calculate the full array size to get the correct offset for the next argument.
266-
// Decrement it by 1, as the normal index increment is still applied.
267-
virtualArgs += getTypeSize(arg.Type)/32 - 1
268-
} else if arg.Type.T == TupleTy && !isDynamicType(arg.Type) {
269-
// If we have a static tuple, like (uint256, bool, uint256), these are
270-
// coded as just like uint256,bool,uint256
271-
virtualArgs += getTypeSize(arg.Type)/32 - 1
272-
}
273-
retval = append(retval, marshalledValue)
274-
}
275-
return retval, nil
276-
}
277-
278-
// UnpackValues can be used to unpack ABI-encoded hexdata according to the ABI-specification,
244+
// UnpackValuesAsStrings can be used to unpack ABI-encoded hexdata according to the ABI-specification,
279245
// without supplying a struct to unpack into. Instead, this method returns a list containing the
280246
// values converted to strings. An atomic argument will be a list with one element.
281247
func (arguments Arguments) UnpackValuesAsStrings(data []byte) ([]interface{}, error) {

accounts/abi/type.go

Lines changed: 0 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -390,166 +390,6 @@ func NewTypeAsString(t string, internalType string, components []ArgumentMarshal
390390
return
391391
}
392392

393-
// NewTypeAsString creates a new reflection type of abi type given in t.
394-
func NewTypeAsString(t string, internalType string, components []ArgumentMarshaling) (typ Type, err error) {
395-
// check that array brackets are equal if they exist
396-
if strings.Count(t, "[") != strings.Count(t, "]") {
397-
return Type{}, errors.New("invalid arg type in abi")
398-
}
399-
typ.stringKind = t
400-
401-
// if there are brackets, get ready to go into slice/array mode and
402-
// recursively create the type
403-
if strings.Count(t, "[") != 0 {
404-
// Note internalType can be empty here.
405-
subInternal := internalType
406-
if i := strings.LastIndex(internalType, "["); i != -1 {
407-
subInternal = subInternal[:i]
408-
}
409-
// recursively embed the type
410-
i := strings.LastIndex(t, "[")
411-
embeddedType, err := NewTypeAsString(t[:i], subInternal, components)
412-
if err != nil {
413-
return Type{}, err
414-
}
415-
// grab the last cell and create a type from there
416-
sliced := t[i:]
417-
// grab the slice size with regexp
418-
re := regexp.MustCompile("[0-9]+")
419-
intz := re.FindAllString(sliced, -1)
420-
421-
if len(intz) == 0 {
422-
// is a slice
423-
typ.T = SliceTy
424-
typ.Elem = &embeddedType
425-
typ.stringKind = embeddedType.stringKind + sliced
426-
} else if len(intz) == 1 {
427-
// is an array
428-
typ.T = ArrayTy
429-
typ.Elem = &embeddedType
430-
typ.Size, err = strconv.Atoi(intz[0])
431-
if err != nil {
432-
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
433-
}
434-
typ.stringKind = embeddedType.stringKind + sliced
435-
} else {
436-
return Type{}, errors.New("invalid formatting of array type")
437-
}
438-
return typ, err
439-
}
440-
// parse the type and size of the abi-type.
441-
matches := typeRegex.FindAllStringSubmatch(t, -1)
442-
if len(matches) == 0 {
443-
return Type{}, fmt.Errorf("invalid type '%v'", t)
444-
}
445-
parsedType := matches[0]
446-
447-
// varSize is the size of the variable
448-
var varSize int
449-
if len(parsedType[3]) > 0 {
450-
var err error
451-
varSize, err = strconv.Atoi(parsedType[2])
452-
if err != nil {
453-
return Type{}, fmt.Errorf("abi: error parsing variable size: %v", err)
454-
}
455-
} else {
456-
if parsedType[0] == "uint" || parsedType[0] == "int" {
457-
// this should fail because it means that there's something wrong with
458-
// the abi type (the compiler should always format it to the size...always)
459-
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
460-
}
461-
}
462-
// varType is the parsed abi type
463-
switch varType := parsedType[1]; varType {
464-
case "int":
465-
typ.Size = varSize
466-
typ.T = IntTy
467-
case "uint":
468-
typ.Size = varSize
469-
typ.T = UintTy
470-
case "bool":
471-
typ.T = BoolTy
472-
case "address":
473-
typ.Size = 20
474-
typ.T = AddressTy
475-
case "string":
476-
typ.T = StringTy
477-
case "bytes":
478-
if varSize == 0 {
479-
typ.T = BytesTy
480-
} else {
481-
if varSize > 32 {
482-
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
483-
}
484-
typ.T = FixedBytesTy
485-
typ.Size = varSize
486-
}
487-
case "tuple":
488-
var (
489-
fields []reflect.StructField
490-
elems []*Type
491-
names []string
492-
expression string // canonical parameter expression
493-
used = make(map[string]bool)
494-
)
495-
expression += "("
496-
for idx, c := range components {
497-
cType, err := NewTypeAsString(c.Type, c.InternalType, c.Components)
498-
if err != nil {
499-
return Type{}, err
500-
}
501-
name := ToCamelCase(c.Name)
502-
if name == "" {
503-
return Type{}, errors.New("abi: purely anonymous or underscored field is not supported")
504-
}
505-
fieldName := ResolveNameConflict(name, func(s string) bool { return used[s] })
506-
if err != nil {
507-
return Type{}, err
508-
}
509-
used[fieldName] = true
510-
if !isValidFieldName(fieldName) {
511-
return Type{}, fmt.Errorf("field %d has invalid name", idx)
512-
}
513-
fields = append(fields, reflect.StructField{
514-
Name: fieldName, // reflect.StructOf will panic for any exported field.
515-
Type: cType.GetTypeAsString(),
516-
Tag: reflect.StructTag("json:\"" + c.Name + "\""),
517-
})
518-
elems = append(elems, &cType)
519-
names = append(names, c.Name)
520-
expression += cType.stringKind
521-
if idx != len(components)-1 {
522-
expression += ","
523-
}
524-
}
525-
expression += ")"
526-
527-
typ.TupleType = reflect.StructOf(fields)
528-
typ.TupleElems = elems
529-
typ.TupleRawNames = names
530-
typ.T = TupleTy
531-
typ.stringKind = expression
532-
533-
const structPrefix = "struct "
534-
// After solidity 0.5.10, a new field of abi "internalType"
535-
// is introduced. From that we can obtain the struct name
536-
// user defined in the source code.
537-
if internalType != "" && strings.HasPrefix(internalType, structPrefix) {
538-
// Foo.Bar type definition is not allowed in golang,
539-
// convert the format to FooBar
540-
typ.TupleRawName = strings.ReplaceAll(internalType[len(structPrefix):], ".", "")
541-
}
542-
543-
case "function":
544-
typ.T = FunctionTy
545-
typ.Size = 24
546-
default:
547-
return Type{}, fmt.Errorf("unsupported arg type: %s", t)
548-
}
549-
550-
return
551-
}
552-
553393
// GetType returns the reflection type of the ABI type.
554394
func (t Type) GetType() reflect.Type {
555395
switch t.T {
@@ -618,42 +458,6 @@ func (t Type) GetTypeAsString() reflect.Type {
618458
}
619459
}
620460

621-
// GetTypeAsString returns the reflection type of the ABI type (always string).
622-
func (t Type) GetTypeAsString() reflect.Type {
623-
switch t.T {
624-
case IntTy:
625-
return reflect.TypeOf("")
626-
case UintTy:
627-
return reflect.TypeOf("")
628-
case BoolTy:
629-
return reflect.TypeOf("")
630-
case StringTy:
631-
return reflect.TypeOf("")
632-
case SliceTy:
633-
return reflect.SliceOf(t.Elem.GetTypeAsString())
634-
case ArrayTy:
635-
return reflect.ArrayOf(t.Size, t.Elem.GetTypeAsString())
636-
case TupleTy:
637-
return t.TupleType
638-
case AddressTy:
639-
return reflect.TypeOf("")
640-
case FixedBytesTy:
641-
return reflect.TypeOf("")
642-
case BytesTy:
643-
return reflect.TypeOf("")
644-
case HashTy:
645-
// hashtype currently not used
646-
return reflect.TypeOf("")
647-
case FixedPointTy:
648-
// fixedpoint type currently not used
649-
return reflect.TypeOf("")
650-
case FunctionTy:
651-
return reflect.TypeOf("")
652-
default:
653-
panic("Invalid type")
654-
}
655-
}
656-
657461
// String implements Stringer.
658462
func (t Type) String() (out string) {
659463
return t.stringKind

ethclient/ethclient.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,14 @@ func (ec *Client) SendTransaction(ctx context.Context, tx *types.Transaction) er
696696
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
697697
}
698698

699+
// SendRawTransaction injects a raw transaction into the pending pool for execution.
700+
//
701+
// If the transaction was a contract creation use the TransactionReceipt method to get the
702+
// contract address after the transaction has been mined.
703+
func (ec *Client) SendRawTransaction(ctx context.Context, rawTx string) error {
704+
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", rawTx)
705+
}
706+
699707
// RevertErrorData returns the 'revert reason' data of a contract call.
700708
//
701709
// This can be used with CallContract and EstimateGas, and only when the server is Geth.
@@ -711,13 +719,6 @@ func RevertErrorData(err error) ([]byte, bool) {
711719
}
712720
}
713721
return nil, false
714-
715-
// SendRawTransaction injects a raw transaction into the pending pool for execution.
716-
//
717-
// If the transaction was a contract creation use the TransactionReceipt method to get the
718-
// contract address after the transaction has been mined.
719-
func (ec *Client) SendRawTransaction(ctx context.Context, rawTx string) error {
720-
return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", rawTx)
721722
}
722723

723724
func toBlockNumArg(number *big.Int) string {

0 commit comments

Comments
 (0)