diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml deleted file mode 100644 index 71b970a..0000000 --- a/.github/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -github: nanmu42 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index fc72752..0000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: CI - -on: - push: - branches: [ master ] - pull_request: - branches: [ master ] - schedule: - - cron: "42 6 * * 0" - -jobs: - build: - environment: "CI Test" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: ">=1.17.4" - - - name: Test - env: - ETHERSCAN_API_KEY: ${{ secrets.ETHERSCAN_API_KEY }} - run: go test -v -coverprofile=coverage.txt -covermode=count ./... - - - name: Codecov - uses: codecov/codecov-action@v2.1.0 - - - name: golangci-lint - uses: golangci/golangci-lint-action@v2 \ No newline at end of file diff --git a/account.go b/account.go index e6a9ac1..4730250 100644 --- a/account.go +++ b/account.go @@ -92,7 +92,10 @@ func (c *Client) ERC20Transfers(contractAddress, address *string, startBlock *in "page": page, "offset": offset, } - compose(param, "contractaddress", contractAddress) + + if contractAddress != nil { + compose(param, "contractaddress", contractAddress) + } compose(param, "address", address) compose(param, "startblock", startBlock) compose(param, "endblock", endBlock) @@ -116,7 +119,9 @@ func (c *Client) ERC721Transfers(contractAddress, address *string, startBlock *i "page": page, "offset": offset, } - compose(param, "contractaddress", contractAddress) + if contractAddress != nil { + compose(param, "contractaddress", contractAddress) + } compose(param, "address", address) compose(param, "startblock", startBlock) compose(param, "endblock", endBlock) @@ -140,7 +145,9 @@ func (c *Client) ERC1155Transfers(contractAddress, address *string, startBlock * "page": page, "offset": offset, } - compose(param, "contractaddress", contractAddress) + if contractAddress != nil { + compose(param, "contractaddress", contractAddress) + } compose(param, "address", address) compose(param, "startblock", startBlock) compose(param, "endblock", endBlock) diff --git a/client.go b/client.go index e69679a..76f046b 100644 --- a/client.go +++ b/client.go @@ -15,6 +15,7 @@ import ( "net/http" "net/http/httputil" "net/url" + "strings" "time" ) @@ -172,7 +173,7 @@ func (c *Client) call(module, action string, param map[string]interface{}, outco err = wrapErr(err, "json unmarshal envelope") return } - if envelope.Status != 1 { + if envelope.Status != 1 && !strings.EqualFold(envelope.Message, "No transactions found") { err = fmt.Errorf("etherscan server: %s", envelope.Message) return } diff --git a/go.mod b/go.mod index 5837de6..2df2b61 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,25 @@ -module github.com/nanmu42/etherscan-api +module github.com/idoall/etherscan-api -go 1.13 +go 1.19 -require github.com/google/go-cmp v0.5.7 +require github.com/google/go-cmp v0.5.9 + +require ( + github.com/bits-and-blooms/bitset v1.13.0 // indirect + github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect + github.com/consensys/bavard v0.1.13 // indirect + github.com/consensys/gnark-crypto v0.12.1 // indirect + github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/ethereum/c-kzg-4844 v0.4.0 // indirect + github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4 // indirect + github.com/ethereum/go-ethereum v1.13.11 // indirect + github.com/holiman/uint256 v1.2.4 // indirect + github.com/mmcloughlin/addchain v0.4.0 // indirect + github.com/supranational/blst v0.3.11 // indirect + golang.org/x/crypto v0.18.0 // indirect + golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/sys v0.17.0 // indirect + rsc.io/tmplfunc v0.0.3 // indirect +) diff --git a/go.sum b/go.sum index a6ca3a4..aed7c2a 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,41 @@ +github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE= +github.com/bits-and-blooms/bitset v1.13.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= +github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/consensys/bavard v0.1.13 h1:oLhMLOFGTLdlda/kma4VOJazblc7IM5y5QPd2A/YjhQ= +github.com/consensys/bavard v0.1.13/go.mod h1:9ItSMtA/dXMAiL7BG6bqW2m3NdSEObYWoH223nGHukI= +github.com/consensys/gnark-crypto v0.12.1 h1:lHH39WuuFgVHONRl3J0LRBtuYdQTumFSDtJF7HpyG8M= +github.com/consensys/gnark-crypto v0.12.1/go.mod h1:v2Gy7L/4ZRosZ7Ivs+9SfUDr0f5UlG+EM5t7MPHiLuY= +github.com/crate-crypto/go-kzg-4844 v0.7.0 h1:C0vgZRk4q4EZ/JgPfzuSoxdCq3C3mOZMBShovmncxvA= +github.com/crate-crypto/go-kzg-4844 v0.7.0/go.mod h1:1kMhvPgI0Ky3yIa+9lFySEBUBXkYxeOi8ZF1sYioxhc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= +github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY= +github.com/ethereum/c-kzg-4844 v0.4.0/go.mod h1:VewdlzQmpT5QSrVhbBuGoCdFJkpaJlO1aQputP83wc0= +github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4 h1:B2mpK+MNqgPqk2/KNi1LbqwtZDy5F7iy0mynQiBr8VA= +github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4/go.mod h1:y4GA2JbAUama1S4QwYjC2hefgGLU8Ul0GMtL/ADMF1c= +github.com/ethereum/go-ethereum v1.13.11 h1:b51Dsm+rEg7anFRUMGB8hODXHvNfcRKzz9vcj8wSdUs= +github.com/ethereum/go-ethereum v1.13.11/go.mod h1:gFtlVORuUcT+UUIcJ/veCNjkuOSujCi338uSHJrYAew= github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= +github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU= +github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= +github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY= +github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU= +github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU= +github.com/supranational/blst v0.3.11 h1:LyU6FolezeWAhvQk0k6O/d49jqgO52MSDDfYgbeoEm4= +github.com/supranational/blst v0.3.11/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= +golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= +golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo= +golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= +golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +rsc.io/tmplfunc v0.0.3 h1:53XFQh69AfOa8Tw0Jm7t+GV7KZhOi6jzsCzTtKbMvzU= +rsc.io/tmplfunc v0.0.3/go.mod h1:AG3sTPzElb1Io3Yg4voV9AGZJuleGAwaVRxL9M49PhA= diff --git a/response.go b/response.go index d096aef..42b7a66 100644 --- a/response.go +++ b/response.go @@ -32,7 +32,7 @@ type AccountBalance struct { // NormalTx holds info from normal tx query type NormalTx struct { - BlockNumber int `json:"blockNumber,string"` + BlockNumber int64 `json:"blockNumber,string"` TimeStamp Time `json:"timeStamp"` Hash string `json:"hash"` Nonce int `json:"nonce,string"` @@ -41,20 +41,22 @@ type NormalTx struct { From string `json:"from"` To string `json:"to"` Value *BigInt `json:"value"` - Gas int `json:"gas,string"` + Gas int64 `json:"gas,string"` GasPrice *BigInt `json:"gasPrice"` IsError int `json:"isError,string"` TxReceiptStatus string `json:"txreceipt_status"` Input string `json:"input"` ContractAddress string `json:"contractAddress"` - CumulativeGasUsed int `json:"cumulativeGasUsed,string"` - GasUsed int `json:"gasUsed,string"` + CumulativeGasUsed int64 `json:"cumulativeGasUsed,string"` + GasUsed int64 `json:"gasUsed,string"` Confirmations int `json:"confirmations,string"` + MethodId string `json:"methodId"` + FunctionName string `json:"functionName"` } // InternalTx holds info from internal tx query type InternalTx struct { - BlockNumber int `json:"blockNumber,string"` + BlockNumber int64 `json:"blockNumber,string"` TimeStamp Time `json:"timeStamp"` Hash string `json:"hash"` From string `json:"from"` @@ -63,8 +65,8 @@ type InternalTx struct { ContractAddress string `json:"contractAddress"` Input string `json:"input"` Type string `json:"type"` - Gas int `json:"gas,string"` - GasUsed int `json:"gasUsed,string"` + Gas int64 `json:"gas,string"` + GasUsed int64 `json:"gasUsed,string"` TraceID string `json:"traceId"` IsError int `json:"isError,string"` ErrCode string `json:"errCode"` @@ -72,10 +74,10 @@ type InternalTx struct { // ERC20Transfer holds info from ERC20 token transfer event query type ERC20Transfer struct { - BlockNumber int `json:"blockNumber,string"` + BlockNumber int64 `json:"blockNumber,string"` TimeStamp Time `json:"timeStamp"` Hash string `json:"hash"` - Nonce int `json:"nonce,string"` + Nonce int64 `json:"nonce,string"` BlockHash string `json:"blockHash"` From string `json:"from"` ContractAddress string `json:"contractAddress"` @@ -85,20 +87,20 @@ type ERC20Transfer struct { TokenSymbol string `json:"tokenSymbol"` TokenDecimal uint8 `json:"tokenDecimal,string"` TransactionIndex int `json:"transactionIndex,string"` - Gas int `json:"gas,string"` + Gas int64 `json:"gas,string"` GasPrice *BigInt `json:"gasPrice"` - GasUsed int `json:"gasUsed,string"` - CumulativeGasUsed int `json:"cumulativeGasUsed,string"` + GasUsed int64 `json:"gasUsed,string"` + CumulativeGasUsed int64 `json:"cumulativeGasUsed,string"` Input string `json:"input"` Confirmations int `json:"confirmations,string"` } // ERC721Transfer holds info from ERC721 token transfer event query type ERC721Transfer struct { - BlockNumber int `json:"blockNumber,string"` + BlockNumber int64 `json:"blockNumber,string"` TimeStamp Time `json:"timeStamp"` Hash string `json:"hash"` - Nonce int `json:"nonce,string"` + Nonce int64 `json:"nonce,string"` BlockHash string `json:"blockHash"` From string `json:"from"` ContractAddress string `json:"contractAddress"` @@ -108,20 +110,20 @@ type ERC721Transfer struct { TokenSymbol string `json:"tokenSymbol"` TokenDecimal uint8 `json:"tokenDecimal,string"` TransactionIndex int `json:"transactionIndex,string"` - Gas int `json:"gas,string"` + Gas int64 `json:"gas,string"` GasPrice *BigInt `json:"gasPrice"` - GasUsed int `json:"gasUsed,string"` - CumulativeGasUsed int `json:"cumulativeGasUsed,string"` + GasUsed int64 `json:"gasUsed,string"` + CumulativeGasUsed int64 `json:"cumulativeGasUsed,string"` Input string `json:"input"` Confirmations int `json:"confirmations,string"` } // ERC1155Transfer holds info from ERC1155 token transfer event query type ERC1155Transfer struct { - BlockNumber int `json:"blockNumber,string"` + BlockNumber int64 `json:"blockNumber,string"` TimeStamp Time `json:"timeStamp"` Hash string `json:"hash"` - Nonce int `json:"nonce,string"` + Nonce int64 `json:"nonce,string"` BlockHash string `json:"blockHash"` From string `json:"from"` ContractAddress string `json:"contractAddress"` @@ -132,10 +134,10 @@ type ERC1155Transfer struct { TokenDecimal uint8 `json:"tokenDecimal,string"` TokenValue uint8 `json:"tokenValue,string"` TransactionIndex int `json:"transactionIndex,string"` - Gas int `json:"gas,string"` + Gas int64 `json:"gas,string"` GasPrice *BigInt `json:"gasPrice"` - GasUsed int `json:"gasUsed,string"` - CumulativeGasUsed int `json:"cumulativeGasUsed,string"` + GasUsed int64 `json:"gasUsed,string"` + CumulativeGasUsed int64 `json:"cumulativeGasUsed,string"` Input string `json:"input"` Confirmations int `json:"confirmations,string"` }