github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/parser/contract_call.go (about)

     1  package parser
     2  
     3  // ContractCall is a call to a smart contract in any of the 3 supported forms
     4  // (see Input syntax above)
     5  type ContractCall struct {
     6  	// Four byte selector, e.g.
     7  	// 0xcdba2fd4(105)
     8  	SelectorCall *SelectorContractCall `parser:"@@"`
     9  
    10  	// Everything encoded, e.g.
    11  	// 0xcdba2fd40000000000000000000000000000000000000000000000000000000000007a69
    12  	Encoded string `parser:" | @Hex"`
    13  
    14  	// Function name, e.g.
    15  	// someName(105)
    16  	FunctionNameCall *FunctionContractCall `parser:" | @@"`
    17  }
    18  
    19  type SelectorContractCall struct {
    20  	Selector  Selector            `parser:"@Hex '('"`
    21  	Arguments []*ContractArgument `parser:" (@@ (',' @@)*)? ')'"`
    22  }
    23  
    24  type FunctionContractCall struct {
    25  	Name      string              `parser:"@SolidityIdent '('"`
    26  	Arguments []*ContractArgument `parser:" (@@ (',' @@)*)? ')'"`
    27  }
    28  
    29  // ParseCall turns smart contract method call string and parses it into
    30  // a nice structures, from which we can easily extract the data to
    31  // make the call.
    32  func ParseCall(source string) (*ContractCall, error) {
    33  	return ourParser.ParseString("", source)
    34  }