From fa51740638f41ef358162808dbdf9b08ee9f04d0 Mon Sep 17 00:00:00 2001 From: rileystephens28 Date: Sun, 13 Oct 2024 17:08:51 -0500 Subject: [PATCH 1/2] Block parsing and qi wallet deserialization fixes --- .../integration/providerdata.integration.test.ts | 2 +- src/providers/abstract-provider.ts | 4 ---- src/providers/formatting.ts | 2 +- src/providers/provider.ts | 4 ++-- src/wallet/payment-codes.ts | 3 +-- src/wallet/qi-hdwallet.ts | 12 ++++++------ 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/_tests/integration/providerdata.integration.test.ts b/src/_tests/integration/providerdata.integration.test.ts index b13725f6..b303cd3e 100644 --- a/src/_tests/integration/providerdata.integration.test.ts +++ b/src/_tests/integration/providerdata.integration.test.ts @@ -211,7 +211,7 @@ describe.skip('Test Provider Block operations', function () { outboundEtxs: rpcBlock.outboundEtxs, hash: rpcBlock.hash, header: { - gasPrice: BigInt(rpcBlock.header.gasPrice), + baseFeePerGas: BigInt(rpcBlock.header.baseFeePerGas), efficiencyScore: BigInt(rpcBlock.header.efficiencyScore), etxEligibleSlices: rpcBlock.header.etxEligibleSlices, etxSetRoot: rpcBlock.header.etxSetRoot, diff --git a/src/providers/abstract-provider.ts b/src/providers/abstract-provider.ts index 71b21630..740862df 100644 --- a/src/providers/abstract-provider.ts +++ b/src/providers/abstract-provider.ts @@ -1000,10 +1000,6 @@ export class AbstractProvider implements Provider { // @todo `network` is not used, remove or re-write // eslint-disable-next-line @typescript-eslint/no-unused-vars _wrapBlock(value: BlockParams, network: Network): Block { - // Handle known node by -> remove null values from the number array - value.header.number = Array.isArray(value.header.number) - ? value.header.number.filter((n: any) => n != null) - : value.header.number; return new Block(formatBlock(value), this); } diff --git a/src/providers/formatting.ts b/src/providers/formatting.ts index 6459e573..c6dab32e 100644 --- a/src/providers/formatting.ts +++ b/src/providers/formatting.ts @@ -24,7 +24,7 @@ export interface BlockParams { } export interface BlockHeaderParams { - gasPrice: null | bigint; + baseFeePerGas: null | bigint; efficiencyScore: bigint; etxEligibleSlices: string; etxSetRoot: string; diff --git a/src/providers/provider.ts b/src/providers/provider.ts index 851eb332..506d13b5 100644 --- a/src/providers/provider.ts +++ b/src/providers/provider.ts @@ -460,7 +460,7 @@ export interface MinedBlock extends Block {} * @category Providers */ export class BlockHeader implements BlockHeaderParams { - readonly gasPrice!: null | bigint; + readonly baseFeePerGas!: null | bigint; readonly efficiencyScore: bigint; readonly etxEligibleSlices: string; readonly etxSetRoot: string; @@ -495,7 +495,7 @@ export class BlockHeader implements BlockHeaderParams { readonly secondaryCoinbase!: string; constructor(params: BlockHeaderParams) { - this.gasPrice = params.gasPrice; + this.baseFeePerGas = params.baseFeePerGas; this.efficiencyScore = params.efficiencyScore; this.etxEligibleSlices = params.etxEligibleSlices; this.etxSetRoot = params.etxSetRoot; diff --git a/src/wallet/payment-codes.ts b/src/wallet/payment-codes.ts index 6d669fa3..2c48260b 100644 --- a/src/wallet/payment-codes.ts +++ b/src/wallet/payment-codes.ts @@ -79,13 +79,12 @@ export class PaymentCodePublic { * * @returns {string} - The Base58 representation of PaymentCode. */ - async toBase58(): Promise { + toBase58(): string { const version = new Uint8Array([PC_VERSION]); const buf = new Uint8Array(version.length + this.buf.length); buf.set(version); buf.set(this.buf, version.length); - // const { bs58check } = await import('@samouraiwallet/bip32/crypto'); return bs58check.encode(buf); } diff --git a/src/wallet/qi-hdwallet.ts b/src/wallet/qi-hdwallet.ts index d829ad67..367669b4 100644 --- a/src/wallet/qi-hdwallet.ts +++ b/src/wallet/qi-hdwallet.ts @@ -1163,6 +1163,10 @@ export class QiHDWallet extends AbstractHDWallet { wallet._usedGapChangeAddresses.push(usedGapChangeAddressInfo); } + // validate and import the payment code info + wallet.validateAndImportPaymentCodeInfo(serialized.receiverPaymentCodeInfo, 'receiver'); + wallet.validateAndImportPaymentCodeInfo(serialized.senderPaymentCodeInfo, 'sender'); + // validate the available outpoints and import them wallet.validateOutpointInfo(serialized.outpoints); wallet._availableOutpoints.push(...serialized.outpoints); @@ -1171,10 +1175,6 @@ export class QiHDWallet extends AbstractHDWallet { wallet.validateOutpointInfo(serialized.pendingOutpoints); wallet._pendingOutpoints.push(...serialized.pendingOutpoints); - // validate and import the payment code info - wallet.validateAndImportPaymentCodeInfo(serialized.receiverPaymentCodeInfo, 'receiver'); - wallet.validateAndImportPaymentCodeInfo(serialized.senderPaymentCodeInfo, 'sender'); - return wallet; } @@ -1272,8 +1272,8 @@ export class QiHDWallet extends AbstractHDWallet { * @param {number} account - The account index to derive the payment code from. * @returns {Promise} A promise that resolves to the Base58-encoded BIP47 payment code. */ - public async getPaymentCode(account: number = 0): Promise { - const privatePcode = await this._getPaymentCodePrivate(account); + public getPaymentCode(account: number = 0): string { + const privatePcode = this._getPaymentCodePrivate(account); return privatePcode.toBase58(); } From ffdd4d3a79832595352ccdb213d980660f3558e8 Mon Sep 17 00:00:00 2001 From: rileystephens28 Date: Sun, 13 Oct 2024 17:29:04 -0500 Subject: [PATCH 2/2] Remove console log from qi wallet --- src/wallet/qi-hdwallet.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wallet/qi-hdwallet.ts b/src/wallet/qi-hdwallet.ts index 367669b4..5b2a5c93 100644 --- a/src/wallet/qi-hdwallet.ts +++ b/src/wallet/qi-hdwallet.ts @@ -475,7 +475,6 @@ export class QiHDWallet extends AbstractHDWallet { // 5.6 Calculate total fee for the transaction using the gasLimit, gasPrice, maxFeePerGas and maxPriorityFeePerGas const totalFee = gasLimit * (feeData.gasPrice ?? 1n) + gasLimit * (feeData.minerTip ?? 0n); - console.log('Total fee:', totalFee); // Get new selection with fee selection = fewestCoinSelector.performSelection(spendTarget, totalFee);