Skip to content

[Feat] Check if valid API#2355

Merged
matiu merged 1 commit into
bitpay:masterfrom
gabrielbazan7:feat/valid
Sep 6, 2019
Merged

[Feat] Check if valid API#2355
matiu merged 1 commit into
bitpay:masterfrom
gabrielbazan7:feat/valid

Conversation

@gabrielbazan7
Copy link
Copy Markdown
Contributor

No description provided.

}

private isValidEthereumAddress(chain, network, add): boolean {
return !!Validation.validateAddress(chain, network, add);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should be able to use Validation.validateAddress for all the chains, otherwise we need to update that method to where that is true.

return !!bitcoreLib.Address.isValid(data, 'testnet');
}

private isValidBitcoinCashLegacyMainnetAddress(data: string): boolean {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Chain specific api logic goes into packages/bitcore-node/src/providers/chain-state/${chain}/${chain}.ts

this.isValidBitcoinCashLegacyMainnetAddress(addr)
);
} else if(chain.toLowerCase() === 'eth') {
return this.isValidEthereumAddress('eth', network, addr);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The ethereum logic can go in packages/bitcore-node/src/modules/ethereum/api/csp.ts

Each chain's CSP should implement this isValidAddress method

@gabrielbazan7 gabrielbazan7 force-pushed the feat/valid branch 2 times, most recently from 767c526 to b06fe9f Compare August 28, 2019 18:04
@gabrielbazan7 gabrielbazan7 changed the title [Feat] Check if valid API WIP [Feat] Check if valid API Aug 28, 2019
getCoinsForTx(params: { chain: string; network: string; txid: string }): Promise<CoinListingJSON>;
getLocalTip(params): Promise<IBlock | null>;
getLocatorHashes(params): Promise<any>;
isValid(params): {isValid: boolean, type:string};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

params: {input: string}

private isValidAddress(params): boolean {
const { chain, network, input } = params;
const addr = this.extractAddress(input);
return this.validateAddress(chain.toLowerCase(), network, addr);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we consolidate the logic of isValidAddress and validateAddress?

does Validation.validateAddress require the adddress to be extracted?

}
}

private isValidBlockOrTx(inputValue): boolean {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

inputValue: string

@gabrielbazan7 gabrielbazan7 changed the title WIP [Feat] Check if valid API [Feat] Check if valid API Aug 29, 2019
micahriggan
micahriggan previously approved these changes Aug 29, 2019
Copy link
Copy Markdown
Contributor

@micahriggan micahriggan left a comment

Choose a reason for hiding this comment

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

Looks good!

getCoinsForTx(params: { chain: string; network: string; txid: string }): Promise<CoinListingJSON>;
getLocalTip(params): Promise<IBlock | null>;
getLocatorHashes(params): Promise<any>;
isValid(params:{ input: string }): {isValid: boolean, type:string};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like chain and network should be in the typing for params, since
const { chain, network, input } = params;

on line 577

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done ! Thanks !

@matiu matiu merged commit 219d7bd into bitpay:master Sep 6, 2019
bsnowden3 pushed a commit to bsnowden3/bitcore that referenced this pull request Sep 11, 2019
bsnowden3 pushed a commit to bsnowden3/bitcore that referenced this pull request Sep 12, 2019
bsnowden3 pushed a commit to bsnowden3/bitcore that referenced this pull request Sep 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants