forked from dominant-strategies/quais.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qi gas fee (dominant-strategies#309)
* refactor coin selection logic to work with denomination indices * refactor coinselector to work with UTXO objects * add new method signature for sendTransaction using paymentCodes * implement sendTransaction with paymentCode * update proto schema for Qi * WIP: add lock field and debug lines * Fix Qi tx submission * fix send Qi with musig * Remove redundent tx type population * Add qi tx fee and force denominating down for outputs * Fix signature decision in qi tx signing * Fix import without file ext * Export serialized wallet types * Remove console logs * Update external deps reference * Apply automatic changes * Apply automatic changes * Fix vulnerable dependency `rollup` * Apply automatic changes --------- Co-authored-by: Alejo Acosta <[email protected]> Co-authored-by: rileystephens28 <[email protected]>
- Loading branch information
1 parent
d4cafe1
commit 0dab9d7
Showing
12 changed files
with
717 additions
and
326 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,80 @@ | ||
const quais = require('../../lib/commonjs/quais'); | ||
require('dotenv').config(); | ||
|
||
// Descrepancy between our serialized data and go quais in that ours in inlcude extra data at the end -> 201406c186bf3b66571cfdd8c7d9336df2298e4d4a9a2af7fcca36fbdfb0b43459a41c45b6c8885dc1f828d44fd005572cbac4cd72dc598790429255d19ec32f7750e | ||
|
||
async function main() { | ||
// Create provider | ||
console.log('RPC URL: ', process.env.RPC_URL); | ||
const provider = new quais.JsonRpcProvider(process.env.RPC_URL); | ||
|
||
// Create wallet and connect to provider | ||
const mnemonic = quais.Mnemonic.fromPhrase(process.env.MNEMONIC); | ||
const aliceQiWallet = quais.QiHDWallet.fromMnemonic(mnemonic); | ||
aliceQiWallet.connect(provider); | ||
|
||
// Initialize Qi wallet | ||
console.log('Initializing Alice wallet...'); | ||
await aliceQiWallet.scan(quais.Zone.Cyprus1); | ||
console.log('Alice wallet scan complete'); | ||
console.log('Serializing Alice wallet...'); | ||
const serializedWallet = aliceQiWallet.serialize(); | ||
|
||
const summary = { | ||
'Total Addresses': serializedWallet.addresses.length, | ||
'Change Addresses': serializedWallet.changeAddresses.length, | ||
'Gap Addresses': serializedWallet.gapAddresses.length, | ||
'Gap Change Addresses': serializedWallet.gapChangeAddresses.length, | ||
Outpoints: serializedWallet.outpoints.length, | ||
'Coin Type': serializedWallet.coinType, | ||
Version: serializedWallet.version, | ||
}; | ||
|
||
console.log('Alice Wallet Summary:'); | ||
console.table(summary); | ||
|
||
const addressTable = serializedWallet.addresses.map((addr) => ({ | ||
PubKey: addr.pubKey, | ||
Address: addr.address, | ||
Index: addr.index, | ||
Change: addr.change ? 'Yes' : 'No', | ||
Zone: addr.zone, | ||
})); | ||
|
||
console.log('\nAlice Wallet Addresses (first 10):'); | ||
console.table(addressTable.slice(0, 10)); | ||
|
||
const outpointsInfoTable = serializedWallet.outpoints.map((outpoint) => ({ | ||
Address: outpoint.address, | ||
Denomination: outpoint.outpoint.denomination, | ||
Index: outpoint.outpoint.index, | ||
TxHash: outpoint.outpoint.txhash, | ||
Zone: outpoint.zone, | ||
Account: outpoint.account, | ||
})); | ||
|
||
console.log('\nAlice Outpoints Info (first 10):'); | ||
console.table(outpointsInfoTable.slice(0, 10)); | ||
|
||
console.log(`Generating Bob's wallet and payment code...`); | ||
const bobMnemonic = quais.Mnemonic.fromPhrase( | ||
'innocent perfect bus miss prevent night oval position aspect nut angle usage expose grace juice', | ||
); | ||
const bobQiWallet = quais.QiHDWallet.fromMnemonic(bobMnemonic); | ||
const bobPaymentCode = await bobQiWallet.getPaymentCode(0); | ||
console.log('Bob Payment code: ', bobPaymentCode); | ||
|
||
// Alice opens a channel to send Qi to Bob | ||
aliceQiWallet.openChannel(bobPaymentCode, 'sender'); | ||
|
||
// Alice sends 1000 Qi to Bob | ||
const tx = await aliceQiWallet.sendTransaction(bobPaymentCode, 750000, quais.Zone.Cyprus1, quais.Zone.Cyprus1); | ||
console.log('Transaction sent: ', tx); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
Large diffs are not rendered by default.
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
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 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
Oops, something went wrong.