-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* caching layer first pass * wire up evm_log_client * start of mapper * .gitignore * update readme * rough draft * address.go * refactor filenames * fix map init * update gitignore * contractInfo cache layer * new op types * cleanup + start of test framework * fix tests + linting errors * fix linter nits * update comments + readme * nits * feedback * construction api * fix linting errors * small bug fixes * naming refactor * data api endpoint * linting fix * edge case cleanup * remove tylersmith lib * start of EnableERC20 config * nits * update config var name * update serviceConfig init * data structure feedback * bug squashing * burn address fix * start of different modes * refactor modes * standard and analytic modes implemented for data ingestion * mapper helper.go file * update formatting * update service config * update address check to toLower * linter clean up * linter clean up * nit cleanup * refactor token whitelist name * refactor indexdefaulttokens * refactor ConvertEVMTopicHashToAddress * continued clean up * increased granularity on erc721 * further cleanup * linter clean up * reorder operations * final clean up * bug fix * linter cleanup * code review feedback * update read.me
- Loading branch information
Showing
24 changed files
with
950 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,5 @@ rosetta-data | |
.avalanchego | ||
*.swp | ||
data | ||
.vscode* | ||
__debug_bin* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/ava-labs/avalanchego/cache" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
) | ||
|
||
const ( | ||
contractCacheSize = 1024 | ||
) | ||
|
||
// ContractClient is a client for the calling contract information | ||
type ContractClient struct { | ||
ethClient *ethclient.Client | ||
cache *cache.LRU | ||
} | ||
|
||
// NewContractClient returns a new ContractInfo client | ||
func NewContractClient(endpoint string) (*ContractClient, error) { | ||
endpoint = strings.TrimSuffix(endpoint, "/") | ||
|
||
c, err := ethclient.Dial(fmt.Sprintf("%s%s", endpoint, prefixEth)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cache := &cache.LRU{Size: contractCacheSize} | ||
|
||
return &ContractClient{ | ||
ethClient: c, | ||
cache: cache, | ||
}, nil | ||
} | ||
|
||
// ContractInfo returns the ContractInfo for a specific address | ||
func (c *ContractClient) ContractInfo(contractAddress common.Address, isErc20 bool) (*ContractInfo, error) { | ||
cachedInfo, isCached := c.cache.Get(contractAddress) | ||
|
||
if isCached { | ||
castCachedInfo := cachedInfo.(*ContractInfo) | ||
return castCachedInfo, nil | ||
} | ||
|
||
token, err := NewContractInfoToken(contractAddress, c.ethClient) | ||
if err != nil { | ||
return nil, err | ||
} | ||
symbol, symbolErr := token.Symbol(nil) | ||
decimals, decimalErr := token.Decimals(nil) | ||
|
||
// Any of these indicate a failure to get complete information from contract | ||
if symbolErr != nil || decimalErr != nil || symbol == "" || decimals == 0 { | ||
if isErc20 { | ||
symbol = UnknownERC20Symbol | ||
decimals = UnknownERC20Decimals | ||
} else { | ||
symbol = UnknownERC721Symbol | ||
decimals = UnknownERC721Decimals | ||
} | ||
} | ||
contractInfo := &ContractInfo{Symbol: symbol, Decimals: decimals} | ||
|
||
// Cache defaults for contract address to avoid unnecessary lookups | ||
c.cache.Put(contractAddress, contractInfo) | ||
return contractInfo, nil | ||
} |
Oops, something went wrong.