Skip to content

Commit

Permalink
Merge pull request #58 from dominant-strategies/reformatTxTypes
Browse files Browse the repository at this point in the history
Reformat tx types
  • Loading branch information
rileystephens28 authored Mar 29, 2024
2 parents f81cfab + e949f4d commit c88189d
Show file tree
Hide file tree
Showing 13 changed files with 3,884 additions and 1,892 deletions.
17 changes: 13 additions & 4 deletions src.ts/providers/abstract-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,13 +1140,22 @@ export class AbstractProvider implements Provider {
});

const tx = Transaction.from(signedTx);
if (tx.hash !== hash) {
throw new Error("@TODO: the returned hash did not match");
}

this.#validateTransactionHash(tx.hash || '', hash)
tx.hash = hash;
return this._wrapTransactionResponse(<any>tx, network).replaceableTransaction(blockNumber);
}

async #validateTransactionHash(computedHash: string, nodehash: string){
if (computedHash.substring(0,4) !== nodehash.substring(0,4))
throw new Error("Transaction hash mismatch in origin Zone");
if (computedHash.substring(6,8) !== nodehash.substring(6,8))
throw new Error("Transaction hash mismatch in destination Zone");
if (parseInt(computedHash[4], 16) < 8 !== parseInt(nodehash[4], 16) < 8)
throw new Error("Transaction ledger mismatch in origin Zone");
if (parseInt(computedHash[8], 16) < 8 !== parseInt(nodehash[8], 16) < 8)
throw new Error("Transaction ledger mismatch in destination Zone");
}

async #getBlock(block: BlockTag | string, includeTransactions: boolean): Promise<any> {
// @TODO: Add CustomBlockPlugin check
if (isHexString(block, 32)) {
Expand Down
12 changes: 3 additions & 9 deletions src.ts/providers/abstract-signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export abstract class AbstractSigner<P extends null | Provider = null | Provider
}

if (pop.gasLimit == null) {
if (tx.type == 0 ) pop.gasLimit = await this.estimateGas(pop);
if (pop.type == 0 ) pop.gasLimit = await this.estimateGas(pop);
else {
//Special cases for type 2 tx to bypass address out of scope in the node
let temp = pop.to
Expand Down Expand Up @@ -133,12 +133,6 @@ export abstract class AbstractSigner<P extends null | Provider = null | Provider
pop.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
}
}

if (pop.type == 2) {
pop.externalGasLimit = getBigInt(Number(pop.gasLimit) * 9);
pop.externalGasTip = getBigInt(Number(pop.maxPriorityFeePerGas) * 9);
pop.externalGasPrice = getBigInt(Number(pop.maxFeePerGas) * 9);
}
//@TOOD: Don't await all over the place; save them up for
// the end for better batching
return await resolveProperties(pop);
Expand All @@ -163,8 +157,8 @@ export abstract class AbstractSigner<P extends null | Provider = null | Provider
delete pop.from;
const txObj = Transaction.from(pop);
const signedTx = await this.signTransaction(txObj);
console.log("signedTX: ", JSON.stringify(txObj))
return await provider.broadcastTransaction(signedTx);
const result = await provider.broadcastTransaction(signedTx);
return result
}

abstract signTransaction(tx: TransactionRequest): Promise<string>;
Expand Down
28 changes: 0 additions & 28 deletions src.ts/providers/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,6 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
creates: allowNull(getAddress, null),

chainId: allowNull(getBigInt, null),

etxGasLimit: allowNull(getBigInt, null),
etxGasPrice: allowNull(getBigInt, null),
etxGasTip: allowNull(getBigInt, null),
etxData: allowNull(formatData, null),
etxAccessList: allowNull(accessListify, null),
}, {
data: [ "input" ],
gasLimit: [ "gas" ],
Expand All @@ -279,28 +273,6 @@ export function formatTransactionResponse(value: any): TransactionResponseParams
result.creates = getCreateAddress(result);
}

if (result.type !== 2) {
delete result.etxGasLimit;
delete result.etxGasPrice;
delete result.etxGasTip;
delete result.etxData;
delete result.etxAccessList;
} else {
//Needed due to go-quai api using both external as naming and etx as naming
//External is for when creating an external transaction
//Etx is for when reading an external transaction
if (result.etxGasLimit == null && value.externalGasLimit!= null)
result.etxGasLimit = value.externalGasLimit;
if (result.etxGasPrice == null && value.externalGasPrice!= null)
result.etxGasPrice = value.externalGasPrice;
if (result.etxGasTip == null && value.externalGasTip!= null)
result.etxGasTip = value.externalGasTip;
if (result.etxData == null && value.externalData!= null)
result.etxData = value.externalData;
if (result.etxAccessList == null && value.externalAccessList!= null)
result.etxAccessList = value.externalAccessList;
}

// Add an access list to supported transaction types
if ((value.type === 1 || value.type === 2) && value.accessList == null) {
result.accessList = [ ];
Expand Down
12 changes: 0 additions & 12 deletions src.ts/providers/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,6 @@ export interface TransactionResponseParams {
* The transaction access list.
*/
accessList: null | AccessList;

//External Transaction fields

etxGasLimit ?: bigint ;

etxGasPrice ?: bigint ;

etxGasTip ?: bigint ;

etxData ?: string ;

etxAccessList ?: AccessList ;
};


60 changes: 0 additions & 60 deletions src.ts/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,6 @@ export interface TransactionRequest {
* the fetch to unexpected parties.
*/
enableCcipRead?: boolean;

/**
* The external gas price.
*/
externalGasPrice?: null | BigNumberish;

/**
* The external gas tip.
*/
externalGasTip?: null | BigNumberish;

/**
* The external gas limit.
*/
externalGasLimit?: null | BigNumberish;


/**
* The external data.
*/
externalData?: null | string;

/**
* The access list for berlin and london transactions.
*/
externalAccessList?: null | AccessListish;
};

/**
Expand Down Expand Up @@ -1387,18 +1361,6 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
*/
readonly accessList!: null | AccessList;

// Extrernal transaction specific fields

readonly etxGasLimit?: bigint ;

readonly etxGasPrice?: bigint ;

readonly etxGasTip?: bigint ;

readonly etxData?: string ;

readonly etxAccessList?: AccessList ;

#startBlock: number;

/**
Expand Down Expand Up @@ -1430,21 +1392,6 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
this.signature = tx.signature;

this.accessList = (tx.accessList != null) ? tx.accessList: null;

if (tx.type != 2) {
delete tx.etxGasLimit;
delete tx.etxGasPrice;
delete tx.etxGasTip;
delete tx.etxData;
delete tx.etxAccessList;
}

if (tx.etxGasLimit) this.etxGasLimit = tx.etxGasLimit;
if (tx.etxGasPrice) this.etxGasPrice = tx.etxGasPrice;
if (tx.etxGasTip) this.etxGasTip = tx.etxGasTip;
if (tx.etxData) this.etxData = tx.etxData;
if (tx.etxAccessList) this.etxAccessList = tx.etxAccessList;

this.#startBlock = -1;
}

Expand All @@ -1455,7 +1402,6 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
const {
blockNumber, blockHash, index, hash, type, to, from, nonce,
data, signature, accessList,
//etxGasLimit, etxGasPrice, etxGasTip, etxData, etxAccessList // Include new fields
} = this;
let result ={
_type: "TransactionReceipt",
Expand All @@ -1468,12 +1414,6 @@ export class TransactionResponse implements TransactionLike<string>, Transaction
maxPriorityFeePerGas: toJson(this.maxPriorityFeePerGas),
nonce, signature, to, index, type,
value: toJson(this.value),
// Include new fields in the output
// etxGasLimit: etxGasLimit ? toJson(etxGasLimit) : null,
// etxGasPrice: etxGasPrice ? toJson(etxGasPrice) : null,
// etxGasTip: etxGasTip ? toJson(etxGasTip) : null,
// etxData: etxData ? etxData : null,
// etxAccessList: etxAccessList ? etxAccessList : null
}

return result;
Expand Down
Loading

0 comments on commit c88189d

Please sign in to comment.