Skip to content

Commit

Permalink
refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
mvadari committed Jun 20, 2023
1 parent 7db620c commit f328b2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
9 changes: 3 additions & 6 deletions packages/xrpl/snippets/src/multisigning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AccountSet,
convertStringToHex,
SignerListSet,
Wallet,
} from '../../src'

const client = new Client('wss://s.altnet.rippletest.net:51233')
Expand All @@ -15,12 +16,8 @@ async function multisigning(): Promise<void> {
* In practice, users generally will not have all keys in one spot,
* hence, users need to implement a way to get signatures.
*/
const { wallet: wallet1 } = await client.fundWallet(null, {
usageContext: 'code snippets',
})
const { wallet: wallet2 } = await client.fundWallet(null, {
usageContext: 'code snippets',
})
const wallet1 = Wallet.generate()
const wallet2 = Wallet.generate()
const { wallet: walletMaster } = await client.fundWallet(null, {
usageContext: 'code snippets',
})
Expand Down
19 changes: 9 additions & 10 deletions packages/xrpl/src/Wallet/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ function multisign(transactions: Array<Transaction | string>): string {
throw new ValidationError('There were 0 transactions to multisign')
}

transactions.forEach((txOrBlob) => {
const tx: Transaction = getDecodedTransaction(txOrBlob)
const decodedTransactions: Transaction[] = transactions.map(
(txOrBlob: string | Transaction) => {
return getDecodedTransaction(txOrBlob)
},
)

decodedTransactions.forEach((tx) => {
/*
* This will throw a more clear error for JS users if any of the supplied transactions has incorrect formatting
*/
Expand All @@ -53,12 +57,6 @@ function multisign(transactions: Array<Transaction | string>): string {
}
})

const decodedTransactions: Transaction[] = transactions.map(
(txOrBlob: string | Transaction) => {
return getDecodedTransaction(txOrBlob)
},
)

validateTransactionEquivalence(decodedTransactions)

return encode(getTransactionWithAllSigners(decodedTransactions))
Expand Down Expand Up @@ -154,10 +152,11 @@ function compareSigners(left: Signer, right: Signer): number {
)
}

const NUM_BITS_IN_HEX = 16

function addressToBigNumber(address: string): BigNumber {
const hex = Buffer.from(decodeAccountID(address)).toString('hex')
const numberOfBitsInHex = 16
return new BigNumber(hex, numberOfBitsInHex)
return new BigNumber(hex, NUM_BITS_IN_HEX)
}

function getDecodedTransaction(txOrBlob: Transaction | string): Transaction {
Expand Down

0 comments on commit f328b2d

Please sign in to comment.