feat: add signature id

This commit is contained in:
Emil Sawicki 2023-06-06 13:35:51 +02:00 committed by Anthony Laibe
parent 9d5b123c95
commit ad9ad4026b
3 changed files with 6 additions and 1 deletions

View File

@ -23,7 +23,7 @@ type Signature struct {
type ByID []Signature
func (s ByID) Len() int { return len(s) }
func (s ByID) Less(i, j int) bool { return s[i].ID < s[j].ID }
func (s ByID) Less(i, j int) bool { return s[i].ID > s[j].ID }
func (s ByID) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
type SignatureList struct {
@ -53,6 +53,7 @@ func (c *Client) Run(data string) (*thirdparty.DataParsed, error) {
return nil, errors.New("input is badly formatted")
}
methodSigData := data[2:10]
fmt.Println(methodSigData)
url := fmt.Sprintf("https://www.4byte.directory/api/v1/signatures/?hex_signature=%s", methodSigData)
resp, err := c.DoQuery(url)
if err != nil {
@ -77,6 +78,7 @@ func (c *Client) Run(data string) (*thirdparty.DataParsed, error) {
results := signatures.Results
sort.Sort(ByID(results))
for _, signature := range results {
id := fmt.Sprintf("0x%x", signature.ID)
name := strings.Split(signature.Text, "(")[0]
rs := rgx.FindStringSubmatch(signature.Text)
@ -102,6 +104,7 @@ func (c *Client) Run(data string) (*thirdparty.DataParsed, error) {
return &thirdparty.DataParsed{
Name: name,
ID: id,
Signature: signature.Text,
Inputs: inputsMapString,
}, nil

View File

@ -12,6 +12,7 @@ func TestRun(t *testing.T) {
require.Nil(t, err)
require.Equal(t, res.Signature, "processDepositQueue(address,uint256)")
require.Equal(t, res.Name, "processDepositQueue")
require.Equal(t, res.ID, "0xf94d2")
require.Equal(t, res.Inputs, map[string]string{
"0": "0x3030303030303030303030303637306463613632",
"1": "44417128579249187980157595307322491418158007948522794164811090501355597543782",

View File

@ -84,6 +84,7 @@ type NFTContractOwnershipProvider interface {
type DataParsed struct {
Name string `json:"name"`
ID string `json:"id"`
Inputs map[string]string `json:"inputs"`
Signature string `json:"signature"`
}