Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre goldenage fixes #318

Merged
merged 2 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/_tests/integration/providerdata.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions src/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,10 +1000,6 @@ export class AbstractProvider<C = FetchRequest> 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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface BlockParams {
}

export interface BlockHeaderParams {
gasPrice: null | bigint;
baseFeePerGas: null | bigint;
efficiencyScore: bigint;
etxEligibleSlices: string;
etxSetRoot: string;
Expand Down
4 changes: 2 additions & 2 deletions src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/wallet/payment-codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ export class PaymentCodePublic {
*
* @returns {string} - The Base58 representation of PaymentCode.
*/
async toBase58(): Promise<string> {
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);
}

Expand Down
13 changes: 6 additions & 7 deletions src/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1163,6 +1162,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);
Expand All @@ -1171,10 +1174,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;
}

Expand Down Expand Up @@ -1272,8 +1271,8 @@ export class QiHDWallet extends AbstractHDWallet {
* @param {number} account - The account index to derive the payment code from.
* @returns {Promise<string>} A promise that resolves to the Base58-encoded BIP47 payment code.
*/
public async getPaymentCode(account: number = 0): Promise<string> {
const privatePcode = await this._getPaymentCodePrivate(account);
public getPaymentCode(account: number = 0): string {
const privatePcode = this._getPaymentCodePrivate(account);
return privatePcode.toBase58();
}

Expand Down
Loading