Skip to content

Commit

Permalink
feat: adding overrides for coredao for non-bitgo recovery support thr…
Browse files Browse the repository at this point in the history
…ough wrw

Ticket: WIN-4290
  • Loading branch information
parasgarg-bitgo committed Jan 16, 2025
1 parent 37f5e49 commit c240b6a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
45 changes: 44 additions & 1 deletion modules/sdk-coin-coredao/src/coredao.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BaseCoin, BitGoBase, common, MPCAlgorithm } from '@bitgo/sdk-core';
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
import { AbstractEthLikeNewCoins, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';
import { AbstractEthLikeNewCoins, optionalDeps, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';
import { TransactionBuilder } from './lib';
import BN from 'bn.js';

export class Coredao extends AbstractEthLikeNewCoins {
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
Expand Down Expand Up @@ -31,4 +32,46 @@ export class Coredao extends AbstractEthLikeNewCoins {
const explorerUrl = common.Environments[this.bitgo.getEnv()].coredaoExplorerBaseUrl;
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
}

/** @inheritDoc */
async queryAddressBalance(address: string): Promise<BN> {
const result = await this.recoveryBlockchainExplorerQuery({
module: 'account',
action: 'balance',
address: address,
});
// throw if the result does not exist or the result is not a valid number
if (!result || !result.result || isNaN(<number>result.result)) {
throw new Error(`Could not obtain address balance for ${address} from the explorer, got: ${result.result}`);
}

if (typeof result.result !== 'string') {
result.result = result.result.toString();
}

return new optionalDeps.ethUtil.BN(result.result, 10);
}

/** @inheritDoc */
async getAddressNonce(address: string): Promise<number> {
// Get nonce for backup key (should be 0)
let nonce = 0;

const result = await this.recoveryBlockchainExplorerQuery({
module: 'account',
action: 'txlist',
sort: 'desc',
address: address,
});
if (!result || !Array.isArray(result.result)) {
throw new Error('Unable to find next nonce from the explorer, got: ' + JSON.stringify(result));
}
const backupKeyTxList = result.result;
if (backupKeyTxList.length > 0) {
// Calculate last nonce used
const outgoingTxs = backupKeyTxList.filter((tx) => tx.from === address);
nonce = Math.max(...outgoingTxs.map((tx) => tx.nonce as number)) + 1;
}
return nonce;
}
}
4 changes: 2 additions & 2 deletions modules/sdk-core/src/bitgo/environments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const mainnetBase: EnvironmentTemplate = {
hmacVerificationEnforced: true,
suiNodeUrl: 'https://fullnode.mainnet.sui.io',
etcNodeUrl: 'https://etc.blockscout.com',
coredaoExplorerBaseUrl: 'https://scan.coredao.org/',
coredaoExplorerBaseUrl: 'https://app.coredao.org/',
oasExplorerBaseUrl: 'https://explorer.oasys.games',
};

Expand Down Expand Up @@ -207,7 +207,7 @@ const testnetBase: EnvironmentTemplate = {
hmacVerificationEnforced: false,
suiNodeUrl: 'https://fullnode.testnet.sui.io',
etcNodeUrl: 'https://etc-mordor.blockscout.com',
coredaoExplorerBaseUrl: 'https://scan.test.btcs.network',
coredaoExplorerBaseUrl: 'https://app.test.btcs.network',
oasExplorerBaseUrl: 'https://explorer.testnet.oasys.games',
};

Expand Down

0 comments on commit c240b6a

Please sign in to comment.