Skip to content

Commit f888c9f

Browse files
author
Mark Toda
committed
Add Statics support
We were differentiating testnet vs mainnet coins based on whether they start with a 't' before. This doesn't work anymore with TRON (symbol trx), so instead we now use statics
1 parent a55d5e6 commit f888c9f

File tree

5 files changed

+1036
-1459
lines changed

5 files changed

+1036
-1459
lines changed

app/sign.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const utxoLib = require('bitgo-utxo-lib');
22
const accountLib = require('@bitgo/account-lib');
3+
const statics = require('@bitgo/statics');
34
const prova = require('prova-lib');
45
const fs = require('fs');
56
const _ = require('lodash');
@@ -231,11 +232,7 @@ const handleSignTrx = function(recoveryRequest, key, skipConfirm) {
231232
}
232233

233234
const backupKeyNode = getHDNodeAndVerify(key, recoveryRequest.backupKey);
234-
try {
235-
builder.sign({ key: backupKeyNode.keyPair.getPrivateKeyBuffer() });
236-
} catch (e) {
237-
console.log(e);
238-
}
235+
builder.sign({ key: backupKeyNode.keyPair.getPrivateKeyBuffer() });
239236
return JSON.stringify(builder.build().toJson());
240237
};
241238

@@ -453,12 +450,11 @@ const handleSign = function(args) {
453450
const file = args.file;
454451

455452
const recoveryRequest = JSON.parse(fs.readFileSync(file, { encoding: 'utf8' }));
456-
let coin = recoveryRequest.coin;
453+
const coin = statics.coins.get(recoveryRequest.coin);
457454

458-
if (coin.startsWith('t')) {
455+
if (coin.network.type === 'testnet') {
459456
bitgo = new bitgojs.BitGo({ env: 'test' });
460457
} else {
461-
console.log('prod');
462458
bitgo = new bitgojs.BitGo({ env: 'prod' });
463459
}
464460

@@ -467,19 +463,19 @@ const handleSign = function(args) {
467463
args.key = prompt("Key: ");
468464
}
469465

470-
const key = parseKey(args.key, coin, args.path);
466+
const key = parseKey(args.key, coin.name, args.path);
471467

472468
let txHex, halfSignedInfo;
473469

474470
// If a tokenContractAddress was provided, use that. Otherwise use the named coin
475-
const basecoin = recoveryRequest.tokenContractAddress ? bitgo.coin(recoveryRequest.tokenContractAddress) : bitgo.coin(coin);
471+
const basecoin = recoveryRequest.tokenContractAddress ? bitgo.coin(recoveryRequest.tokenContractAddress) : bitgo.coin(coin.name);
476472

477473
switch (basecoin.getFamily()) {
478474
case 'eth':
479475
if (recoveryRequest.txPrebuild) {
480476
halfSignedInfo = handleHalfSignEth(recoveryRequest, key, args.confirm, basecoin);
481477
} else {
482-
if (coin.getChain() === 'eth' || coin.getChain() === 'teth') {
478+
if (coin.family === 'eth' && !coin.isToken) {
483479
txHex = handleSignEthereum(recoveryRequest, key, args.confirm);
484480
} else {
485481
txHex = handleSignErc20(recoveryRequest, key, args.confirm, basecoin);

config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ module.exports = {
2222
txrp: 'xpub',
2323
dash: 'xpub',
2424
tdash: 'xpub',
25+
trx: 'xpub',
26+
ttrx: 'xpub',
2527
xlm: 'xlm',
26-
txlm: 'xlm'
28+
txlm: 'xlm',
2729
},
2830
"host": "0.0.0.0",
2931
"port": 6833,

0 commit comments

Comments
 (0)