-
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.
Merge pull request #3741 from BitGo/EA-658-sanitize-script
feat(bitgo): add example to sanitize unwitnessed txn from cardano cli
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// There are known serialization inconsistencies between the cardano-cli and nodejs libraries. As a workaround, ADA pledge txn | ||
// needs to be re-serialized using the nodejs library before witnessed by node key and then submitted to BitGo pledge endpoint. | ||
// This script helps to re-serialize the pledge txn using the nodejs library. | ||
const fs = require('fs'); | ||
const BitGoJS = require('bitgo'); | ||
const { Transaction } = require('@bitgo/sdk-coin-ada'); | ||
const bitgo = new BitGoJS.BitGo({ env: 'test' }); | ||
const coin = 'tada'; | ||
const basecoin = bitgo.coin(coin); | ||
|
||
const unwitnessedTxCborHex = 'replaced by CBOR hex of unwitnessed tx from cardano-cli'; | ||
|
||
const tx = new Transaction(basecoin); | ||
tx.fromRawTransaction(unwitnessedTxCborHex); | ||
const sanitizedUnwitnessedTxn = tx.toBroadcastFormat(); | ||
|
||
const unwitnessedTxn = JSON.stringify( | ||
{ | ||
type: 'Unwitnessed Tx BabbageEra', | ||
description: 'Ledger Cddl Format', | ||
cborHex: sanitizedUnwitnessedTxn, | ||
}, | ||
null, | ||
4 | ||
); | ||
|
||
fs.writeFile('sanitized_unwitnessed_pledge_txn.tx', unwitnessedTxn, (err) => { | ||
if (err) { | ||
console.error('Error writing to sanitized txn.', err); | ||
} else { | ||
console.log('Successfully saved to sanitized txn.'); | ||
} | ||
}); |