Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ContractKit to get addresses for Blockchain API #1175

Merged
merged 20 commits into from
Oct 7, 2019

Conversation

annakaz
Copy link
Contributor

@annakaz annakaz commented Oct 1, 2019

Description

Use ContractKit to get addresses for Blockchain API.

Notes that the faucet address and verification rewards address remain hardcoded, as these are not stored in the Contract Registry / available from ContractKit.

Tested

Ran tests.

Have not yet tested deploying to a dev environment

Other changes

Modified tests to not be dependent on live network contract addresses

Related issues

Backwards compatibility

Yes

@annakaz
Copy link
Contributor Author

annakaz commented Oct 1, 2019

Note that changes to .yaml files assume that all networks have a hosted node at https://{NETWORK_NAME}-infura.celo-testnet.org/

@codecov
Copy link

codecov bot commented Oct 1, 2019

Codecov Report

Merging #1175 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1175   +/-   ##
=======================================
  Coverage   66.47%   66.47%           
=======================================
  Files         262      262           
  Lines        7648     7648           
  Branches      441      441           
=======================================
  Hits         5084     5084           
  Misses       2464     2464           
  Partials      100      100
Flag Coverage Δ
#mobile 66.47% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 78afc93...06ecea5. Read the comment docs.

Copy link
Contributor

@jmrossy jmrossy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, been wanting to see this fixed for a long time!! Just a few small comments below

@@ -16,6 +16,7 @@
"deploy": "./deploy.sh"
},
"dependencies": {
"@celo/contractkit": "0.1.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should use 0.1.6 if we're keeping to the scheme we decided in #eng-typescript
https://celo-org.slack.com/archives/CL6JFBALE/p1569937790004100

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, sorry, looks like this isn't quite as decided as I thought it was. See continued discussion here:
https://celo-org.slack.com/archives/CL6JFBALE/p1570136686024300

@@ -51,6 +45,8 @@ export interface BlockscoutTransaction {
}

export class BlockscoutAPI extends RESTDataSource {
tokenAddressMapping: { [key: string]: string } | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why we cache these values here in this class and also in the utils file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cached these both places to avoid passing them back and forth. I realize this isn't the cleanest solution, but the alternatives of:

  • Only caching them in the class, and passing them (sometimes undefined) in as parameters to the getter function is a weird pattern
  • Only caching them in the function, and needing to call and store the addresses in the class each time they're used
    Seemed less desirable

Copy link
Contributor

@jmrossy jmrossy Oct 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only caching them in the function, and needing to call and store the addresses

Maybe I'm missing something but why does the class need to store the addresses at all when they'll always be available in util's module-level cache after first retrieval? Can't we just call get every time we want them?

let attestationsAddress: string
let tokenAddressMapping: { [key: string]: string }
export async function getContractAddresses() {
if (goldTokenAddress && stableTokenAddress && attestationsAddress) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some error handling around this function contents would be good.


let contractKit: ContractKit
export async function getContractKit(): Promise<ContractKit> {
if (contractKit && (await contractKit.isListening())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here

@annakaz annakaz assigned annakaz and unassigned cmcewen Oct 3, 2019
@@ -16,6 +16,7 @@
"deploy": "./deploy.sh"
},
"dependencies": {
"@celo/contractkit": "0.1.6",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@annakaz this isn't available on npm so we should use 0.1.5

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.1.6 has now been published, so leaving this version as is
https://www.npmjs.com/package/@celo/contractkit

if (goldTokenAddress && stableTokenAddress && attestationsAddress) {
console.info('Already got token addresses')
return { tokenAddressMapping, attestationsAddress }
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: No need for this else, the if statement returns
See here:
https://stackoverflow.com/questions/268132/invert-if-statement-to-reduce-nesting

if (contractKit && (await contractKit.isListening())) {
// Already connected
return contractKit
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -131,7 +166,7 @@ export class BlockscoutAPI extends RESTDataSource {
value: new BigNumber(event.value).dividedBy(WEI_PER_GOLD).toNumber(),
address,
comment,
symbol: CONTRACT_SYMBOL_MAPPING[event.contractAddress.toLowerCase()] || 'unknown',
symbol: this.getTokenAtAddress(event.contractAddress) || 'unknown',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one you provide a fallback value, but not the for the other uses of getTokenAtAddress - might be nice to standardize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback above isn't provided as it's for an exchange with our Exchange contract, which must be between gold and dollars.

The fallback here is for any token transfer, which could be of a new Token whose address we don't recognize

@annakaz annakaz added the automerge Have PR merge automatically when checks pass label Oct 7, 2019
@ashishb ashishb merged commit 9a50adf into master Oct 7, 2019
@ashishb ashishb deleted the annakaz/blockchainapi-ck branch October 7, 2019 20:32
aaronmgdr added a commit that referenced this pull request Oct 8, 2019
* master: (35 commits)
  [Wallet] Fix top of emojis cut off in the activity feed (#1243)
  Adding a contract to store minimum required client version (#1081)
  Revert "Feature #909 proxy delegatecall (#1152)" (#1241)
  Use ContractKit to get addresses for Blockchain API (#1175)
  Feature #909 proxy delegatecall (#1152)
  Fix Faucet done message (#1217)
  Updated SETUP.md with new yarn process (#1224)
  Adding `increaseAllowance` and `decreaseAllowance` methods (#1196)
  extracting function signatures (#1061)
  Fix integration hardcode (#1208)
  Fixing flaky governance test (#1155)
  Restore CI branch (#1223)
  [wallet] e2e back to green (#1210)
  [Wallet] Implement new import wallet flow designs (#1209)
  [Wallet] Fix disable conditions for butons on Enter Invite screen (#1214)
  [protocol] Rename infrastructureFraction to proposerFraction (#1174)
  [ck] Proper promise treatment to avoid UnhandledPromises (#1219)
  [ck] Transform StableToken parameters from fixidity format (#1218)
  [wallet]Store encrypted local signing key (#1188)
  2019-10-03 alfajores deployment (#1200)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Have PR merge automatically when checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blockchain Api uses Contract Kit
4 participants