-
Notifications
You must be signed in to change notification settings - Fork 277
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
refactor(abstract-eth): move txBuilder to abstract-eth #4030
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a093f16
refactor(abstract-eth): move txbuilder to abstract-eth
gianchandania 8b09148
refactor(sdk-coin-polygon): make changes related to txbuilder refactor
gianchandania 0460371
refactor(sdk-coin-arbeth): make changes related to txbuilder refactor
gianchandania 1288d10
refactor(sdk-coin-opeth): make changes related to txbuilder refactor
gianchandania 0933e3e
refactor(sdk-coin-ethw): make changes related to txbuilder refactor
gianchandania 519fe47
fix(sdk-core): fix issue related to bignumber version
gianchandania 52396ed
refactor(abstract-eth): delete mpc related classes
gianchandania 286ccfd
fix(sdk-coin-eth): fix issue related to ethtxbuilder
gianchandania File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
import debugLib from 'debug'; | ||
import { bip32 } from '@bitgo/utxo-lib'; | ||
import { | ||
BitGoBase, | ||
EthereumLibraryUnavailableError, | ||
Recipient, | ||
TransactionRecipient, | ||
TransactionPrebuild as BaseTransactionPrebuild, | ||
} from '@bitgo/sdk-core'; | ||
import { BaseCoin as StaticsBaseCoin, CoinFamily, EthereumNetwork as EthLikeNetwork } from '@bitgo/statics'; | ||
import type * as EthLikeTxLib from '@ethereumjs/tx'; | ||
import type * as EthLikeCommon from '@ethereumjs/common'; | ||
|
||
import { AbstractEthLikeCoin } from './abstractEthLikeCoin'; | ||
|
||
/** | ||
* The prebuilt hop transaction returned from the HSM | ||
*/ | ||
interface HopPrebuild { | ||
tx: string; | ||
id: string; | ||
signature: string; | ||
paymentId: string; | ||
gasPrice: number; | ||
gasLimit: number; | ||
amount: number; | ||
recipient: string; | ||
nonce: number; | ||
userReqSig: string; | ||
gasPriceMax: number; | ||
} | ||
|
||
export interface TransactionPrebuild extends BaseTransactionPrebuild { | ||
hopTransaction?: HopPrebuild; | ||
buildParams: { | ||
recipients: Recipient[]; | ||
}; | ||
recipients: TransactionRecipient[]; | ||
nextContractSequenceId: string; | ||
gasPrice: number; | ||
gasLimit: number; | ||
isBatch: boolean; | ||
coin: string; | ||
token?: string; | ||
} | ||
|
||
const debug = debugLib('bitgo:v2:ethlike'); | ||
|
||
export const optionalDeps = { | ||
get ethAbi() { | ||
try { | ||
return require('ethereumjs-abi'); | ||
} catch (e) { | ||
debug('unable to load ethereumjs-abi:'); | ||
debug(e.stack); | ||
throw new EthereumLibraryUnavailableError(`ethereumjs-abi`); | ||
} | ||
}, | ||
|
||
get ethUtil() { | ||
try { | ||
return require('ethereumjs-util'); | ||
} catch (e) { | ||
debug('unable to load ethereumjs-util:'); | ||
debug(e.stack); | ||
throw new EthereumLibraryUnavailableError(`ethereumjs-util`); | ||
} | ||
}, | ||
|
||
get EthTx(): typeof EthLikeTxLib { | ||
try { | ||
return require('@ethereumjs/tx'); | ||
} catch (e) { | ||
debug('unable to load @ethereumjs/tx'); | ||
debug(e.stack); | ||
throw new EthereumLibraryUnavailableError(`@ethereumjs/tx`); | ||
} | ||
}, | ||
|
||
get EthCommon(): typeof EthLikeCommon { | ||
try { | ||
return require('@ethereumjs/common'); | ||
} catch (e) { | ||
debug('unable to load @ethereumjs/common:'); | ||
debug(e.stack); | ||
throw new EthereumLibraryUnavailableError(`@ethereumjs/common`); | ||
} | ||
}, | ||
}; | ||
|
||
export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin { | ||
protected readonly sendMethodName: 'sendMultiSig' | 'sendMultiSigToken'; | ||
|
||
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>; | ||
private static _ethLikeCoin: Readonly<StaticsBaseCoin>; | ||
|
||
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) { | ||
super(bitgo, staticsCoin); | ||
|
||
if (!staticsCoin) { | ||
throw new Error('missing required constructor parameter staticsCoin'); | ||
} | ||
|
||
this._staticsCoin = staticsCoin; | ||
AbstractEthLikeNewCoins._ethLikeCoin = staticsCoin; | ||
this.sendMethodName = 'sendMultiSig'; | ||
} | ||
|
||
readonly staticsCoin?: Readonly<StaticsBaseCoin>; | ||
|
||
getChain() { | ||
return this._staticsCoin.name; | ||
} | ||
|
||
/** | ||
* Get the base chain that the coin exists on. | ||
*/ | ||
getBaseChain() { | ||
return this.getChain(); | ||
} | ||
|
||
getFamily(): CoinFamily { | ||
return this._staticsCoin.family; | ||
} | ||
|
||
getNetwork(): EthLikeNetwork | undefined { | ||
return this._staticsCoin?.network as EthLikeNetwork; | ||
} | ||
|
||
getFullName() { | ||
return this._staticsCoin.fullName; | ||
} | ||
|
||
getBaseFactor() { | ||
return Math.pow(10, this._staticsCoin.decimalPlaces); | ||
} | ||
|
||
/** @inheritDoc */ | ||
isEVM(): boolean { | ||
return true; | ||
} | ||
|
||
valuelessTransferAllowed(): boolean { | ||
return true; | ||
} | ||
|
||
/** | ||
* Evaluates whether an address string is valid for this coin | ||
* @param address | ||
*/ | ||
isValidAddress(address: string): boolean { | ||
return optionalDeps.ethUtil.isValidAddress(optionalDeps.ethUtil.addHexPrefix(address)); | ||
} | ||
|
||
/** | ||
* Return boolean indicating whether input is valid public key for the coin. | ||
* | ||
* @param {String} pub the pub to be checked | ||
* @returns {Boolean} is it valid? | ||
*/ | ||
isValidPub(pub: string): boolean { | ||
try { | ||
return bip32.fromBase58(pub).isNeutered(); | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Flag for sending data along with transactions | ||
* @returns {boolean} True if okay to send tx data (ETH), false otherwise | ||
*/ | ||
transactionDataAllowed() { | ||
return true; | ||
} | ||
|
||
/** | ||
* Default gas price from platform | ||
* @returns {BigNumber} | ||
*/ | ||
getRecoveryGasPrice(): any { | ||
return new optionalDeps.ethUtil.BN('20000000000'); | ||
} | ||
|
||
/** | ||
* Default gas limit from platform | ||
* @returns {BigNumber} | ||
*/ | ||
getRecoveryGasLimit(): any { | ||
return new optionalDeps.ethUtil.BN('500000'); | ||
} | ||
|
||
/** | ||
* Default expire time for a contract call (1 week) | ||
* @returns {number} Time in seconds | ||
*/ | ||
getDefaultExpireTime(): number { | ||
return Math.floor(new Date().getTime() / 1000) + 60 * 60 * 24 * 7; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './abstractEthLikeCoin'; | ||
export * from './ethLikeToken'; | ||
export * from './abstractEthLikeMPCCoin'; | ||
export * from './ethLikeMPCToken'; | ||
export * from './lib'; | ||
export * from './abstractEthLikeNewCoins'; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export * from './contractCall'; | ||
export * from './iface'; | ||
export * from './keyPair'; | ||
export * from './transaction'; | ||
export * from './transactionBuilder'; | ||
export * from './transferBuilder'; | ||
export * from './transferBuilders'; | ||
export * from './transferBuilder'; | ||
export * from './types'; | ||
export * from './utils'; | ||
export * from './walletUtil'; | ||
|
||
// for Backwards Compatibility | ||
import * as Interface from './iface'; | ||
import * as Utils from './utils'; | ||
|
||
export { Interface, Utils }; |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified this method because TransactionBuilder in abstract-eth is an abstract class and we can't instantiate the abstract class