-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GA-fix: fixes addresses imported via private key not initiating trans…
…actions
- Loading branch information
1 parent
c3f10d2
commit 7ef4881
Showing
2 changed files
with
88 additions
and
91 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
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,70 @@ | ||
import { SignedTransaction } from "../../networks" | ||
|
||
export const parseAndValidateSignedTransaction = ( | ||
tx: any, | ||
network: any | ||
): SignedTransaction => { | ||
if (!tx.hash || !tx.from || !tx.r || !tx.s || typeof tx.v === "undefined") { | ||
throw new Error("Transaction doesn't appear to have been signed.") | ||
} | ||
|
||
const { | ||
to, | ||
gasPrice, | ||
gasLimit, | ||
maxFeePerGas, | ||
maxPriorityFeePerGas, | ||
externalGasLimit, | ||
externalGasPrice, | ||
externalGasTip, | ||
hash, | ||
from, | ||
nonce, | ||
data, | ||
value, | ||
type, | ||
r, | ||
s, | ||
v, | ||
} = tx | ||
|
||
const baseSignedTx = { | ||
hash, | ||
from, | ||
to, | ||
nonce, | ||
input: data, | ||
value: value.toBigInt(), | ||
type: type as 0, | ||
gasLimit: gasLimit.toBigInt(), | ||
r, | ||
s, | ||
v, | ||
blockHash: null, | ||
blockHeight: null, | ||
asset: network.baseAsset, | ||
network: network, | ||
} | ||
|
||
const signedTx: SignedTransaction = | ||
typeof maxPriorityFeePerGas === "undefined" || | ||
typeof maxFeePerGas === "undefined" | ||
? { | ||
...baseSignedTx, | ||
gasPrice: gasPrice?.toBigInt() ?? null, | ||
maxFeePerGas: null, | ||
maxPriorityFeePerGas: null, | ||
} | ||
: { | ||
...baseSignedTx, | ||
gasPrice: null, | ||
maxFeePerGas: maxFeePerGas.toBigInt(), | ||
maxPriorityFeePerGas: maxPriorityFeePerGas.toBigInt(), | ||
externalGasLimit: externalGasLimit?.toBigInt(), | ||
externalGasPrice: externalGasPrice?.toBigInt(), | ||
externalGasTip: externalGasTip?.toBigInt(), | ||
type: type as 0 | 2 | 1 | 100 | null, | ||
} | ||
|
||
return signedTx | ||
} |