mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
1 parent
b7a28dbfaa
commit
3fc1614ce0
6 files changed
+421
No files matched your search
@@ -152,6 +152,7 @@
|
||||
"email-bounce-parser-browser": "^1.1.0",
|
||||
"email-normalizer": "^1.0.0",
|
||||
"emojilib": "^4.0.2",
|
||||
"ethers": "^6.15.0",
|
||||
"event-cron-parser": "^1.0.35",
|
||||
"exif-be-gone": "^1.5.1",
|
||||
"exifreader": "^4.26.1",
|
||||
|
||||
Generated
+74
@@ -344,6 +344,9 @@ importers:
|
||||
emojilib:
|
||||
specifier: ^4.0.2
|
||||
version: 4.0.2
|
||||
ethers:
|
||||
specifier: ^6.15.0
|
||||
version: 6.15.0
|
||||
event-cron-parser:
|
||||
specifier: ^1.0.35
|
||||
version: 1.0.35
|
||||
@@ -1165,6 +1168,9 @@ packages:
|
||||
resolution: {integrity: sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
'@adraffy/ens-normalize@1.10.1':
|
||||
resolution: {integrity: sha512-96Z2IP3mYmF1Xg2cDm8f1gWGf/HUVedQ3FMifV4kG/PQ4yEP51xDtRAEfhVNt5f/uzpNkZHwWQuUcu6D6K+Ekw==}
|
||||
|
||||
'@ampproject/remapping@2.2.1':
|
||||
resolution: {integrity: sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
@@ -3234,6 +3240,13 @@ packages:
|
||||
resolution: {integrity: sha512-rONPWMC7PeExE077uLE4oqWrZ1IvAfz3oH9LibVAcVCopJiA9R62uavnbEzdkVmJYI6M6Zgkbeb07+tWjlq2XA==}
|
||||
engines: {node: ^14.21.3 || >=16}
|
||||
|
||||
'@noble/curves@1.2.0':
|
||||
resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==}
|
||||
|
||||
'@noble/hashes@1.3.2':
|
||||
resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==}
|
||||
engines: {node: '>= 16'}
|
||||
|
||||
'@nodelib/fs.scandir@2.1.5':
|
||||
resolution: {integrity: sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==}
|
||||
engines: {node: '>= 8'}
|
||||
@@ -4142,6 +4155,9 @@ packages:
|
||||
'@types/node@22.18.11':
|
||||
resolution: {integrity: sha512-Gd33J2XIrXurb+eT2ktze3rJAfAp9ZNjlBdh4SVgyrKEOADwCbdUDaK7QgJno8Ue4kcajscsKqu6n8OBG3hhCQ==}
|
||||
|
||||
'@types/node@22.7.5':
|
||||
resolution: {integrity: sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==}
|
||||
|
||||
'@types/node@24.3.0':
|
||||
resolution: {integrity: sha512-aPTXCrfwnDLj4VvXrm+UUCQjNEvJgNA8s5F1cvwQU+3KNltTOkBm1j30uNLyqqPNe7gE3KFzImYoZEfLhp4Yow==}
|
||||
|
||||
@@ -4804,6 +4820,9 @@ packages:
|
||||
resolution: {integrity: sha512-ynZ4w/nUUv5rrsR8UUGoe1VC9hZj6V5hU9Qw1HlMDJGEJw5S7TfTErWTjMys6M7vr0YWcPqs3qAr4ss0nDfP+A==}
|
||||
engines: {node: '>=0.8'}
|
||||
|
||||
aes-js@4.0.0-beta.5:
|
||||
resolution: {integrity: sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==}
|
||||
|
||||
agent-base@6.0.2:
|
||||
resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==}
|
||||
engines: {node: '>= 6.0.0'}
|
||||
@@ -6575,6 +6594,10 @@ packages:
|
||||
resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
ethers@6.15.0:
|
||||
resolution: {integrity: sha512-Kf/3ZW54L4UT0pZtsY/rf+EkBU7Qi5nnhonjUb8yTXcxH3cdcWrV2cRyk0Xk/4jK6OoHhxxZHriyhje20If2hQ==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
|
||||
event-cron-parser@1.0.35:
|
||||
resolution: {integrity: sha512-3vF/wHmzG4r0cufQWUEwo0APhf1pS6sux01RhK38GQxQ5Hwyxn6NYVUvRAFanoRScM5f3mzH2KsrOPgzb569kg==}
|
||||
|
||||
@@ -10373,6 +10396,9 @@ packages:
|
||||
tslib@1.14.1:
|
||||
resolution: {integrity: sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==}
|
||||
|
||||
tslib@2.7.0:
|
||||
resolution: {integrity: sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==}
|
||||
|
||||
tslib@2.8.1:
|
||||
resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==}
|
||||
|
||||
@@ -10530,6 +10556,9 @@ packages:
|
||||
resolution: {integrity: sha512-tO/bf30wBbTsJ7go80j0RzA2rcwX6o7XPBpeFcb+jzoeb4pfMM2zUeSDIkY1AWqeZabWxaQZ/h8N9t35QKDLPQ==}
|
||||
engines: {node: '>=10.13.0'}
|
||||
|
||||
undici-types@6.19.8:
|
||||
resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==}
|
||||
|
||||
undici-types@6.21.0:
|
||||
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
|
||||
|
||||
@@ -11271,6 +11300,18 @@ packages:
|
||||
wrappy@1.0.2:
|
||||
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
|
||||
|
||||
ws@8.17.1:
|
||||
resolution: {integrity: sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
peerDependencies:
|
||||
bufferutil: ^4.0.1
|
||||
utf-8-validate: '>=5.0.2'
|
||||
peerDependenciesMeta:
|
||||
bufferutil:
|
||||
optional: true
|
||||
utf-8-validate:
|
||||
optional: true
|
||||
|
||||
ws@8.18.0:
|
||||
resolution: {integrity: sha512-8VbfWfHLbbwu3+N6OKsOMpBdT4kXPDDB9cJk2bJ6mh9ucxdlnNvH1e+roYkKmN9Nxw2yjz7VzeO9oOz2zJ04Pw==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
@@ -11438,6 +11479,8 @@ snapshots:
|
||||
|
||||
'@aashutoshrathi/word-wrap@1.2.6': {}
|
||||
|
||||
'@adraffy/ens-normalize@1.10.1': {}
|
||||
|
||||
'@ampproject/remapping@2.2.1':
|
||||
dependencies:
|
||||
'@jridgewell/gen-mapping': 0.3.3
|
||||
@@ -14133,6 +14176,12 @@ snapshots:
|
||||
|
||||
'@noble/ciphers@1.2.1': {}
|
||||
|
||||
'@noble/curves@1.2.0':
|
||||
dependencies:
|
||||
'@noble/hashes': 1.3.2
|
||||
|
||||
'@noble/hashes@1.3.2': {}
|
||||
|
||||
'@nodelib/fs.scandir@2.1.5':
|
||||
dependencies:
|
||||
'@nodelib/fs.stat': 2.0.5
|
||||
@@ -15055,6 +15104,10 @@ snapshots:
|
||||
dependencies:
|
||||
undici-types: 6.21.0
|
||||
|
||||
'@types/node@22.7.5':
|
||||
dependencies:
|
||||
undici-types: 6.19.8
|
||||
|
||||
'@types/node@24.3.0':
|
||||
dependencies:
|
||||
undici-types: 7.10.0
|
||||
@@ -15967,6 +16020,8 @@ snapshots:
|
||||
|
||||
adler-32@1.3.1: {}
|
||||
|
||||
aes-js@4.0.0-beta.5: {}
|
||||
|
||||
agent-base@6.0.2:
|
||||
dependencies:
|
||||
debug: 4.4.0
|
||||
@@ -17977,6 +18032,19 @@ snapshots:
|
||||
|
||||
esutils@2.0.3: {}
|
||||
|
||||
ethers@6.15.0:
|
||||
dependencies:
|
||||
'@adraffy/ens-normalize': 1.10.1
|
||||
'@noble/curves': 1.2.0
|
||||
'@noble/hashes': 1.3.2
|
||||
'@types/node': 22.7.5
|
||||
aes-js: 4.0.0-beta.5
|
||||
tslib: 2.7.0
|
||||
ws: 8.17.1
|
||||
transitivePeerDependencies:
|
||||
- bufferutil
|
||||
- utf-8-validate
|
||||
|
||||
event-cron-parser@1.0.35:
|
||||
dependencies:
|
||||
number-to-words: 1.2.4
|
||||
@@ -22188,6 +22256,8 @@ snapshots:
|
||||
|
||||
tslib@1.14.1: {}
|
||||
|
||||
tslib@2.7.0: {}
|
||||
|
||||
tslib@2.8.1: {}
|
||||
|
||||
tsutils@3.21.0(typescript@5.2.2):
|
||||
@@ -22333,6 +22403,8 @@ snapshots:
|
||||
last-run: 2.0.0
|
||||
undertaker-registry: 2.0.0
|
||||
|
||||
undici-types@6.19.8: {}
|
||||
|
||||
undici-types@6.21.0: {}
|
||||
|
||||
undici-types@7.10.0: {}
|
||||
@@ -23299,6 +23371,8 @@ snapshots:
|
||||
|
||||
wrappy@1.0.2: {}
|
||||
|
||||
ws@8.17.1: {}
|
||||
|
||||
ws@8.18.0: {}
|
||||
|
||||
wsemi@1.7.64:
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import JSON5 from 'json5';
|
||||
import { ethers } from 'ethers';
|
||||
import { decodeTransaction } from './eth-transaction-decoder.service';
|
||||
|
||||
// Minimal ABI for testing
|
||||
const transferAbi = JSON5.stringify([
|
||||
{
|
||||
inputs: [
|
||||
{ internalType: 'address', name: 'to', type: 'address' },
|
||||
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
|
||||
],
|
||||
name: 'transfer',
|
||||
outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function',
|
||||
},
|
||||
]);
|
||||
|
||||
describe('decodeTransaction', () => {
|
||||
it('decodes a valid transaction', () => {
|
||||
const iface = new ethers.Interface(JSON5.parse(transferAbi));
|
||||
const data = iface.encodeFunctionData('transfer', [
|
||||
'0x000000000000000000000000000000000000dead',
|
||||
1000n,
|
||||
]);
|
||||
|
||||
const txJson = JSON5.stringify({
|
||||
from: '0x1111111111111111111111111111111111111111',
|
||||
to: '0x2222222222222222222222222222222222222222',
|
||||
data,
|
||||
value: '0',
|
||||
gas: '21000',
|
||||
gasPrice: ethers.parseUnits('5', 'gwei').toString(),
|
||||
nonce: 1,
|
||||
});
|
||||
|
||||
const result = decodeTransaction(transferAbi, txJson);
|
||||
|
||||
expect(result).toEqual({
|
||||
args: [
|
||||
'0x000000000000000000000000000000000000dEaD',
|
||||
1000n,
|
||||
],
|
||||
fragment: {
|
||||
constant: false,
|
||||
gas: null,
|
||||
inputs: [
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'address',
|
||||
components: null,
|
||||
name: 'to',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'uint256',
|
||||
components: null,
|
||||
name: 'amount',
|
||||
type: 'uint256',
|
||||
},
|
||||
],
|
||||
name: 'transfer',
|
||||
outputs: [
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'bool',
|
||||
components: null,
|
||||
name: '',
|
||||
type: 'bool',
|
||||
},
|
||||
],
|
||||
payable: false,
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function',
|
||||
},
|
||||
from: '0x1111111111111111111111111111111111111111',
|
||||
gas: '21000',
|
||||
gasPrice: '5.0 gwei',
|
||||
method: 'transfer',
|
||||
nonce: 1,
|
||||
outputJson: {
|
||||
inputs: [
|
||||
'0x000000000000000000000000000000000000dEaD',
|
||||
{
|
||||
hex: '0x3e8',
|
||||
type: 'BigNumber',
|
||||
},
|
||||
],
|
||||
method: 'transfer',
|
||||
names: [
|
||||
'to',
|
||||
'amount',
|
||||
],
|
||||
types: [
|
||||
'address',
|
||||
'uint256',
|
||||
],
|
||||
},
|
||||
signature: 'transfer(address,uint256)',
|
||||
to: '0x2222222222222222222222222222222222222222',
|
||||
value: '0.0',
|
||||
});
|
||||
});
|
||||
|
||||
it('decode raw transaction', () => {
|
||||
const abi = '[{"constant":false,"inputs":[{"name":"newAddr","type":"address"}],"name":"setFoundationWallet","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalUnrestrictedAssignments","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"getState","outputs":[{"name":"","type":"uint8"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"round0StartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"round0Target","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"minDonation","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"weiDonated","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"},{"name":"a","type":"uint256"},{"name":"b","type":"uint256"}],"name":"multFracCeiling","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalRestrictedTokens","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"round1BonusSteps","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"newAuth","type":"address"}],"name":"setExchangeRateAuth","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"round1StartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"round1EndTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"maxRoundDelay","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"n","type":"uint256"}],"name":"getPhaseStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"time","type":"uint256"}],"name":"getMultiplierAtTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"id","type":"uint256"}],"name":"targetReached","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"}],"name":"finalize","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"assignmentsClosed","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"donorList","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"phaseLength","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"addr","type":"address"},{"name":"timestamp","type":"uint256"},{"name":"chfCents","type":"uint256"},{"name":"currency","type":"string"},{"name":"memo","type":"bytes32"}],"name":"registerOffChainDonation","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"gracePeriodAfterRound1Target","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalRestrictedAssignments","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"burnMultNom","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"foundationWallet","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"gracePeriodAfterRound0Target","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"finalizeStartTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"finalizeEndTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"donationRound","type":"uint256"},{"name":"dfnAddr","type":"address"},{"name":"fwdAddr","type":"address"}],"name":"getStatus","outputs":[{"name":"currentState","type":"uint8"},{"name":"fxRate","type":"uint256"},{"name":"currentMultiplier","type":"uint256"},{"name":"donationCount","type":"uint256"},{"name":"totalTokenAmount","type":"uint256"},{"name":"startTime","type":"uint256"},{"name":"endTime","type":"uint256"},{"name":"isTargetReached","type":"bool"},{"name":"chfCentsDonated","type":"uint256"},{"name":"tokenAmount","type":"uint256"},{"name":"fwdBalance","type":"uint256"},{"name":"donated","type":"uint256"}],"Line truncated
|
||||
const rawTransaction = '0x67043cae0000000000000000000000005a9dac9315fdd1c3d13ef8af7fdfeb522db08f020000000000000000000000000000000000000000000000000000000058a20230000000000000000000000000000000000000000000000000000000000040293400000000000000000000000000000000000000000000000000000000000000a0f3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c800000000000000000000000000000000000000000000000000000000000000034254430000000000000000000000000000000000000000000000000000000000';
|
||||
|
||||
expect(decodeTransaction(abi, rawTransaction)).toEqual({
|
||||
args: [
|
||||
'0x5A9dAC9315FdD1c3D13eF8Af7FDFEB522Db08F02',
|
||||
1487012400n,
|
||||
4204852n,
|
||||
'BTC',
|
||||
'0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8',
|
||||
],
|
||||
fragment: {
|
||||
constant: false,
|
||||
gas: null,
|
||||
inputs: [
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'address',
|
||||
components: null,
|
||||
name: 'addr',
|
||||
type: 'address',
|
||||
},
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'uint256',
|
||||
components: null,
|
||||
name: 'timestamp',
|
||||
type: 'uint256',
|
||||
},
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'uint256',
|
||||
components: null,
|
||||
name: 'chfCents',
|
||||
type: 'uint256',
|
||||
},
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'string',
|
||||
components: null,
|
||||
name: 'currency',
|
||||
type: 'string',
|
||||
},
|
||||
{
|
||||
arrayChildren: null,
|
||||
arrayLength: null,
|
||||
baseType: 'bytes32',
|
||||
components: null,
|
||||
name: 'memo',
|
||||
type: 'bytes32',
|
||||
},
|
||||
],
|
||||
name: 'registerOffChainDonation',
|
||||
outputs: [],
|
||||
payable: false,
|
||||
stateMutability: 'nonpayable',
|
||||
type: 'function',
|
||||
},
|
||||
from: undefined,
|
||||
gas: undefined,
|
||||
gasPrice: undefined,
|
||||
method: 'registerOffChainDonation',
|
||||
nonce: undefined,
|
||||
outputJson: {
|
||||
inputs: [
|
||||
'0x5A9dAC9315FdD1c3D13eF8Af7FDFEB522Db08F02',
|
||||
{
|
||||
hex: '0x58a20230',
|
||||
type: 'BigNumber',
|
||||
},
|
||||
{
|
||||
hex: '0x402934',
|
||||
type: 'BigNumber',
|
||||
}, 'BTC',
|
||||
'0xf3df64775a2dfb6bc9e09dced96d0816ff5055bf95da13ce5b6c3f53b97071c8',
|
||||
],
|
||||
method: 'registerOffChainDonation',
|
||||
names: [
|
||||
'addr',
|
||||
'timestamp',
|
||||
'chfCents',
|
||||
'currency',
|
||||
'memo',
|
||||
],
|
||||
types: [
|
||||
'address',
|
||||
'uint256',
|
||||
'uint256',
|
||||
'string',
|
||||
'bytes32',
|
||||
],
|
||||
},
|
||||
signature: 'registerOffChainDonation(address,uint256,uint256,string,bytes32)',
|
||||
to: undefined,
|
||||
value: '0',
|
||||
});
|
||||
});
|
||||
|
||||
it('throws if data does not start with 0x', () => {
|
||||
const badTx = JSON5.stringify({ data: '1234' });
|
||||
expect(() => decodeTransaction(transferAbi, badTx)).toThrowError(
|
||||
'Transaction data must start with 0x',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import JSON5 from 'json5';
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
export function decodeTransaction(abiContract: string, transactionJson: string) {
|
||||
const abi = JSON5.parse(abiContract);
|
||||
const iface = new ethers.Interface(abi);
|
||||
const tx = transactionJson.startsWith('0x')
|
||||
? { data: transactionJson?.trim() }
|
||||
: JSON5.parse(transactionJson);
|
||||
|
||||
if (!tx.data || !tx.data.startsWith('0x')) {
|
||||
throw new Error('Transaction data must start with 0x');
|
||||
}
|
||||
|
||||
const parsed = iface.parseTransaction({ data: tx.data });
|
||||
if (parsed === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const types = parsed.fragment.inputs.map((input: any) => input.type);
|
||||
const names = parsed!.fragment.inputs.map((input: any) => input.name);
|
||||
const inputs = parsed.args.map((arg: any) => {
|
||||
if (typeof arg === 'bigint') {
|
||||
return { type: 'BigNumber', hex: `0x${arg.toString(16)}` };
|
||||
}
|
||||
return arg;
|
||||
});
|
||||
|
||||
const outputJson = {
|
||||
method: parsed.name,
|
||||
names,
|
||||
types,
|
||||
inputs,
|
||||
};
|
||||
|
||||
return {
|
||||
from: tx.from,
|
||||
to: tx.to,
|
||||
value: tx.value ? ethers.formatEther(tx.value) : '0',
|
||||
gas: tx.gas,
|
||||
gasPrice: tx.gasPrice ? `${ethers.formatUnits(tx.gasPrice, 'gwei')} gwei` : undefined,
|
||||
nonce: tx.nonce,
|
||||
method: parsed.name,
|
||||
signature: parsed.signature,
|
||||
args: parsed.args,
|
||||
fragment: JSON.parse(JSON.stringify(parsed.fragment)),
|
||||
outputJson,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<script setup lang="ts">
|
||||
import { decodeTransaction } from './eth-transaction-decoder.service';
|
||||
|
||||
const abi = ref('');
|
||||
const txJson = ref('');
|
||||
const error = ref('');
|
||||
const decoded = computed(() => {
|
||||
error.value = '';
|
||||
try {
|
||||
return decodeTransaction(abi.value, txJson.value);
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = e.toString();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<NFormItem label="Smart Contract ABI:" mb-2>
|
||||
<NInput v-model:value="abi" type="textarea" placeholder="Paste ABI JSON here" rows="6" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Raw Transaction (0x...) or JSON Transaction:" mb-2>
|
||||
<NInput v-model:value="txJson" type="textarea" placeholder="{"to":"0x...","data":"0x..."} or raw 0x...." rows="6" />
|
||||
</NFormItem>
|
||||
|
||||
<n-alert v-if="error">
|
||||
{{ error }}
|
||||
</n-alert>
|
||||
|
||||
<c-card v-if="decoded" title="Decoded Transaction" mb-2>
|
||||
<NFormItem label="From">
|
||||
<input-copyable :value="decoded.from || 'N/A'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="To">
|
||||
<input-copyable :value="decoded.to || 'N/A'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Value">
|
||||
<input-copyable :value="decoded.value || '0'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Gas">
|
||||
<input-copyable :value="decoded.gas || 'N/A'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Gas Price">
|
||||
<input-copyable :value="decoded.gasPrice || 'N/A'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Nonce">
|
||||
<input-copyable :value="decoded.nonce || 'N/A'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Method">
|
||||
<input-copyable :value="decoded.method || 'N/A'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Signature">
|
||||
<input-copyable :value="decoded.signature || 'N/A'" />
|
||||
</NFormItem>
|
||||
<NFormItem label="Arguments">
|
||||
<textarea-copyable language="json" :value="JSON.stringify(decoded.args, null, 2)" />
|
||||
</NFormItem>
|
||||
</c-card>
|
||||
|
||||
<c-card v-if="decoded" title="Structured Output JSON">
|
||||
<textarea-copyable language="json" :value="JSON.stringify(decoded.outputJson, null, 2)" />
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ReportMoney } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'ETH Transaction Decoder',
|
||||
path: '/eth-transaction-decoder',
|
||||
description: 'Ethereum transaction decoder with Smart Contract ABI',
|
||||
keywords: ['eth', 'ethereum', 'transaction', 'decoder'],
|
||||
component: () => import('./eth-transaction-decoder.vue'),
|
||||
icon: ReportMoney,
|
||||
createdAt: new Date('2025-11-01'),
|
||||
category: 'Forensic',
|
||||
});
|
||||
Reference in new issue
Block a user