-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(sdk-coin-xrp): add transaction builder
- Loading branch information
Showing
18 changed files
with
1,446 additions
and
17 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
export * from './xrp'; | ||
export * from './txrp'; | ||
export * from './lib'; | ||
export * from './register'; | ||
export * from './lib/iface'; | ||
export * from './lib/utils'; | ||
export * from './txrp'; | ||
export * from './xrp'; | ||
export * from './xrpToken'; |
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,73 @@ | ||
import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core'; | ||
import { BaseCoin as CoinConfig } from '@bitgo/statics'; | ||
import { AccountSet } from 'xrpl'; | ||
import { XrpTransactionType } from './iface'; | ||
import { Transaction } from './transaction'; | ||
import { TransactionBuilder } from './transactionBuilder'; | ||
import utils from './utils'; | ||
|
||
export class AccountSetBuilder extends TransactionBuilder { | ||
protected _setFlag: number; | ||
protected _messageKey: string; | ||
constructor(_coinConfig: Readonly<CoinConfig>) { | ||
super(_coinConfig); | ||
} | ||
|
||
protected get transactionType(): TransactionType { | ||
return TransactionType.AccountUpdate; | ||
} | ||
|
||
protected get xrpTransactionType(): XrpTransactionType.AccountSet { | ||
return XrpTransactionType.AccountSet; | ||
} | ||
|
||
setFlag(setFlag: number): TransactionBuilder { | ||
utils.validateAccountSetFlag(setFlag); | ||
this._setFlag = setFlag; | ||
return this; | ||
} | ||
|
||
messageKey(messageKey: string): TransactionBuilder { | ||
if (typeof messageKey !== 'string') { | ||
throw new BuildTransactionError('Invalid message key'); | ||
} | ||
this._messageKey = messageKey; | ||
return this; | ||
} | ||
|
||
initBuilder(tx: Transaction): void { | ||
super.initBuilder(tx); | ||
|
||
const { setFlag, messageKey } = tx.toJson(); | ||
if (setFlag) { | ||
this.setFlag(setFlag); | ||
} | ||
|
||
if (messageKey) { | ||
this.messageKey(messageKey); | ||
} | ||
} | ||
|
||
/** @inheritdoc */ | ||
protected async buildImplementation(): Promise<Transaction> { | ||
if (!this._sender) { | ||
throw new BuildTransactionError('Sender must be set before building the transaction'); | ||
} | ||
|
||
const accountSetFields: AccountSet = { | ||
TransactionType: this.xrpTransactionType, | ||
Account: this._sender, | ||
}; | ||
if (this._setFlag) { | ||
accountSetFields.SetFlag = this._setFlag; | ||
} | ||
|
||
if (this._messageKey) { | ||
accountSetFields.MessageKey = this._messageKey; | ||
} | ||
|
||
this._specificFields = accountSetFields; | ||
|
||
return await super.buildImplementation(); | ||
} | ||
} |
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,28 @@ | ||
// https://xrpl.org/signerlistset.html | ||
export const MAX_SIGNERS = 32; | ||
export const MIN_SIGNERS = 1; | ||
export const MIN_SIGNER_QUORUM = 1; | ||
|
||
// https://xrpl.org/accountset.html#accountset-flags | ||
export const VALID_ACCOUNT_SET_FLAGS = [ | ||
5, // asfAccountTxnID | ||
16, // asfAllowTrustLineClawback | ||
10, // asfAuthorizedNFTokenMinter | ||
8, // asfDefaultRipple | ||
9, // asfDepositAuth | ||
4, // asfDisableMaster | ||
13, // asfDisallowIncomingCheck | ||
12, // asfDisallowIncomingNFTokenOffer | ||
14, // asfDisallowIncomingPayChan | ||
15, // asfDisallowIncomingTrustline | ||
3, // asfDisallowXRP | ||
7, // asfGlobalFreeze | ||
6, // asfNoFreeze | ||
2, // asfRequireAuth | ||
1, // asfRequireDest | ||
]; | ||
|
||
// Global flags for bitgo address | ||
export const USER_KEY_SETTING_FLAG = 65536; | ||
export const MASTER_KEY_DEACTIVATION_FLAG = 1048576; | ||
export const REQUIRE_DESTINATION_TAG_FLAG = 131072; |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Utils from './utils'; | ||
|
||
export * from './constants'; | ||
export * from './iface'; | ||
export { AccountSetBuilder } from './accountSetBuilder'; | ||
export { KeyPair } from './keyPair'; | ||
export { Transaction } from './transaction'; | ||
export { TransactionBuilder } from './transactionBuilder'; | ||
export { TransactionBuilderFactory } from './transactionBuilderFactory'; | ||
export { TransferBuilder } from './transferBuilder'; | ||
export { WalletInitializationBuilder } from './walletInitializationBuilder'; | ||
export { Utils }; |
Oops, something went wrong.