-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: calculate tx hash before seal #337
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { ethErrors } from 'eth-rpc-errors'; | |
import * as ethUtil from 'ethereumjs-util'; | ||
import { getApp } from 'firebase/app'; | ||
import { getAuth } from 'firebase/auth/web-extension'; | ||
import { encode } from 'rlp'; | ||
import web3, { TransactionError } from 'web3'; | ||
|
||
import { | ||
|
@@ -71,7 +72,6 @@ import { getStoragedAccount } from '../utils/getStoragedAccount'; | |
|
||
import BaseController from './base'; | ||
import provider from './provider'; | ||
|
||
interface Keyring { | ||
type: string; | ||
getAccounts(): Promise<string[]>; | ||
|
@@ -1651,7 +1651,6 @@ export class WalletController extends BaseController { | |
}); | ||
} | ||
|
||
console.log('v2data ', transformedArray, address); | ||
const active = await userWalletService.getActiveWallet(); | ||
if (!active) { | ||
// userInfoService.addUserId(v2data.data.id); | ||
|
@@ -1664,7 +1663,6 @@ export class WalletController extends BaseController { | |
getUserWallets = async (): Promise<WalletResponse[]> => { | ||
const network = await this.getNetwork(); | ||
const wallets = await userWalletService.getUserWallets(network); | ||
console.log('getUserWallets ', wallets); | ||
if (!wallets[0]) { | ||
await this.refreshUserWallets(); | ||
const data = await userWalletService.getUserWallets(network); | ||
|
@@ -1705,7 +1703,6 @@ export class WalletController extends BaseController { | |
|
||
getCurrentWallet = async () => { | ||
const wallet = await userWalletService.getCurrentWallet(); | ||
console.log('getCurrentWallet ', wallet); | ||
if (!wallet.address) { | ||
const network = await this.getNetwork(); | ||
await this.refreshUserWallets(); | ||
|
@@ -2218,24 +2215,43 @@ export class WalletController extends BaseController { | |
fcl.arg(gasLimit, t.UInt64), | ||
]); | ||
|
||
let evmAddress = await this.getEvmAddress(); | ||
|
||
mixpanelTrack.track('ft_transfer', { | ||
from_address: await this.getEvmAddress(), | ||
from_address: evmAddress, | ||
to_address: to, | ||
amount: parseFloat(amount), | ||
ft_identifier: 'FLOW', | ||
type: 'evm', | ||
}); | ||
|
||
console.log('result ', result); | ||
const res = await fcl.tx(result).onceSealed(); | ||
const transactionExecutedEvent = res.events.find((event) => | ||
event.type.includes('TransactionExecuted') | ||
); | ||
if (evmAddress.startsWith('0x')) { | ||
evmAddress = evmAddress.substring(2); | ||
} | ||
|
||
const addressNonce = await this.getNonce(evmAddress); | ||
|
||
if (transactionExecutedEvent) { | ||
const hash = transactionExecutedEvent.data.hash; | ||
const hashHexString = hash.map((num) => parseInt(num).toString(16).padStart(2, '0')).join(''); | ||
const keccak256 = (data: Buffer) => { | ||
return ethUtil.keccak256(data); | ||
}; | ||
|
||
// [nonce, gasPrice, gasLimit, to.addressData, value, data, v, r, s] | ||
const transaction = [ | ||
Number(addressNonce), // nonce | ||
0, // Fixed value | ||
gasLimit, // Gas Limit | ||
Buffer.from(to, 'hex'), // To Address | ||
BigInt(amount * 10 ** 18), // Value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BigInt(number) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the amount is already a number |
||
Buffer.from(dataArray), // Call Data | ||
255, // Fixed value | ||
BigInt('0x' + evmAddress), // From Account | ||
5, // SubType | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for 255 and 5. const directCallTxType = 255
const contractCallSubType = 5 |
||
]; | ||
|
||
const encodedData = encode(transaction); | ||
const hash = keccak256(Buffer.from(encodedData)); | ||
const hashHexString = Buffer.from(hash).toString('hex'); | ||
if (hashHexString) { | ||
return hashHexString; | ||
} else { | ||
console.log('Transaction Executed event not found'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use the variable instead of magic number ?