@@ -12,14 +12,21 @@ import { ValidatedRelayRequest } from './types/relay'
12
12
import * as grpc from '@grpc/grpc-js'
13
13
import { readConfig } from './config/config.js'
14
14
import pino from 'pino'
15
+ import { TransactionReceipt } from 'web3-core'
15
16
16
17
let client : Client < typeof Protocol > | null = null
17
18
19
+ type CoreRelayResponse = {
20
+ txhash : string
21
+ block : bigint
22
+ blockhash : string
23
+ }
24
+
18
25
export const coreRelay = async (
19
26
logger : pino . Logger ,
20
27
requestId : string ,
21
28
request : ValidatedRelayRequest
22
- ) => {
29
+ ) : Promise < TransactionReceipt | null > => {
23
30
try {
24
31
if ( client === null ) {
25
32
const config = readConfig ( )
@@ -38,16 +45,16 @@ export const coreRelay = async (
38
45
entityType,
39
46
action,
40
47
metadata : metadataAny ,
41
- subjectSig
42
- // nonce: nonceBytes
48
+ subjectSig,
49
+ nonce : nonceBytes
43
50
} = decodeAbi ( encodedABI )
44
51
45
52
const signer = request . senderAddress
46
53
const userId = BigInt ( userIdBig . toString ( ) )
47
54
const entityId = BigInt ( entityIdBig . toString ( ) )
48
- const metadata = JSON . stringify ( metadataAny )
55
+ const metadata = metadataAny as string
49
56
const signature = ethers . utils . hexlify ( subjectSig )
50
- // const nonce = ethers.utils.hexlify(nonceBytes)
57
+ const nonce = ethers . utils . hexlify ( nonceBytes )
51
58
52
59
const manageEntity = create ( ManageEntityLegacySchema , {
53
60
userId,
@@ -57,7 +64,7 @@ export const coreRelay = async (
57
64
metadata,
58
65
signature,
59
66
signer,
60
- nonce : BigInt ( 1 ) ,
67
+ nonce,
61
68
} )
62
69
63
70
const signedTransaction = create ( SignedTransactionSchema , {
@@ -77,11 +84,28 @@ export const coreRelay = async (
77
84
logger . info (
78
85
{
79
86
tx : transaction ,
80
- txhash : txhash
87
+ txhash : txhash ,
88
+ block : res . blockHeight ,
89
+ blockhash : res . blockHash
81
90
} ,
82
91
'core relay success'
83
92
)
93
+ return {
94
+ status : true ,
95
+ transactionHash : txhash ,
96
+ transactionIndex : 0 ,
97
+ blockHash : res . blockHash ,
98
+ blockNumber : Number ( res . blockHeight ) ,
99
+ from : signer || "" ,
100
+ to : signer || "" ,
101
+ cumulativeGasUsed : 10 ,
102
+ gasUsed : 10 ,
103
+ effectiveGasPrice : 420 ,
104
+ logs : [ ] ,
105
+ logsBloom : ""
106
+ }
84
107
} catch ( e ) {
85
108
logger . error ( { err : e } , 'core relay failure:' )
109
+ return null
86
110
}
87
111
}
0 commit comments