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

Add RSK support to Bitcore Wallet Client #3300

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/bitcore-wallet-client/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var Bitcore_ = {
eth: CWC.BitcoreLib,
xrp: CWC.BitcoreLib,
doge: CWC.BitcoreLibDoge,
ltc: CWC.BitcoreLibLtc
ltc: CWC.BitcoreLibLtc,
rsk: CWC.BitcoreLib
};
var Mnemonic = require('bitcore-mnemonic');
var url = require('url');
Expand Down Expand Up @@ -468,7 +469,7 @@ export class API extends EventEmitter {
if (!_.includes(Constants.COINS, coin))
return cb(new Error('Invalid coin'));

if (coin == 'eth')
if (coin == 'eth' || coin == 'rsk' || coin == 'rbtc')
return cb(new Error('ETH not supported for this action'));

var B = Bitcore_[coin];
Expand Down Expand Up @@ -703,6 +704,7 @@ export class API extends EventEmitter {
switch (chain) {
case 'XRP':
case 'ETH':
case 'RSK':
const unsignedTxs = t.uncheckedSerialize();
const signedTxs = [];
for (let index = 0; index < signatures.length; index++) {
Expand Down Expand Up @@ -2515,7 +2517,7 @@ export class API extends EventEmitter {
// * @return {Callback} cb - Return error (if exists) and nonce
// */
getNonce(opts, cb) {
$.checkArgument(opts.coin == 'eth', 'Invalid coin: must be "eth"');
$.checkArgument(opts.coin == 'eth' || opts.coin == 'rsk' || opts.coin == 'rbtc', 'Invalid coin: must be "eth"');
Copy link
Author

@alepc253 alepc253 Nov 8, 2021

Choose a reason for hiding this comment

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

BTW, I'm using both RSK and RBTC because I detected in the frontend an assumption that "chain" and "coin" are the same and this is not true for RSK (RSK is the chain and RBTC the coin/native ticker)


var qs = [];
qs.push(`coin=${opts.coin}`);
Expand Down Expand Up @@ -2933,6 +2935,8 @@ export class API extends EventEmitter {
['doge', 'testnet'],
['ltc', 'testnet'],
['ltc', 'livenet'],
['rsk', 'livenet'],
['rbtc', 'livenet'],
['btc', 'livenet', true],
['bch', 'livenet', true],
['doge', 'livenet', true],
Expand Down
4 changes: 3 additions & 1 deletion packages/bitcore-wallet-client/src/lib/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const Constants = {
'gusd',
'busd',
'dai',
'wbtc'
'wbtc',
'rsk',
'rbtc'
],
ERC20: ['usdc', 'pax', 'gusd', 'busd', 'dai', 'wbtc'],
UTXO_COINS: ['btc', 'bch', 'doge', 'ltc'],
Expand Down
3 changes: 2 additions & 1 deletion packages/bitcore-wallet-client/src/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const Bitcore_ = {
eth: Bitcore,
xrp: Bitcore,
doge: BitcoreLibDoge,
ltc: BitcoreLibLtc
ltc: BitcoreLibLtc,
rsk: Bitcore
};
const PrivateKey = Bitcore.PrivateKey;
const PublicKey = Bitcore.PublicKey;
Expand Down
2 changes: 2 additions & 0 deletions packages/bitcore-wallet-client/src/lib/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ export class Credentials {
coin = '3';
} else if (this.coin == 'ltc') {
coin = '2';
} else if (this.coin == 'rsk' || this.coin == 'rbtc') {
coin = '137';
} else {
throw new Error('unknown coin: ' + this.coin);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/bitcore-wallet-client/src/lib/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ export class Key {
coinCode = '3';
} else if (opts.coin == 'ltc') {
coinCode = '2';
} else if (opts.coin == 'rsk' || opts.coin == 'rbtc') {
coinCode = '137';
} else {
throw new Error('unknown coin: ' + opts.coin);
}
Expand Down