I’m using a simple variant of the moralis bridge.
Moralis.Cloud.afterSave("EthTokenTransfers", (request) => {
18 const data = JSON.parse(JSON.stringify(request.object, ["token_address", "to_address", "from_address","transaction_hash","value", "confirmed"]));
19 logger.info(data);
20 if (data["token_address"] == mainToken_address.toLocaleLowerCase() && data["to_address"] == MainBridge_address.toLocaleLowerCase() && !data["confirmed"]) {
21 const txlock = processBridgeRequestLock(data);
22 const txbridge = processBridgeRequestBridge(data);
23 }
24 else{
25 logger.info("transaction not related to bridge");
26 }
27 async function processBridgeRequestLock(data) {
28 logger.info("bridging starting locking tokens");
29 const functionCall = MainBridge.methods.lockTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
30 const gatewayNonce = web3Main.eth.getTransactionCount(gateway_address);
31 const transactionBody = {
32 to: MainBridge_address,
33 nonce:gatewayNonce,
34 data:functionCall,
35 gas:400000,
36 gasPrice:web3Main.utils.toWei("100", "gwei")
37 }
38 signedTransaction = await web3Main.eth.accounts.signTransaction(transactionBody,gatewayKey);
39 logger.info(signedTransaction.transactionHash);
40 fulfillTx = await web3Main.eth.sendSignedTransaction(signedTransaction.rawTransaction);
41 logger.info("fulfillTx: " + JSON.stringify(fulfillTx));
42 }
43 async function processBridgeRequestBridge(data) {
44 logger.info("bridging tokens");
45 const functionCall = SideBridge.methods.bridgeTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
46 const gatewayNonce = web3Side.eth.getTransactionCount(gateway_address);
47 const transactionBody = {
48 to: SideBridge_address,
49 nonce:gatewayNonce,
50 data:functionCall,
51 gas:400000,
52 gasPrice:web3Side.utils.toWei("15", "gwei")
53 }
54 signedTransaction = await web3Side.eth.accounts.signTransaction(transactionBody,gatewayKey);
55 logger.info(signedTransaction.transactionHash);
56 fulfillTx = await web3Side.eth.sendSignedTransaction(signedTransaction.rawTransaction);
57 logger.info("fulfillTx: " + JSON.stringify(fulfillTx))
58 return fulfillTx;
59 }
60});
61
62
63Moralis.Cloud.afterSave("BscTokenTransfers", (request) => {
64 const data = JSON.parse(JSON.stringify(request.object, ["token_address", "to_address", "from_address","transaction_hash","value", "confirmed"]));
65 logger.info(data);
66 if (data["token_address"] == childToken_address.toLocaleLowerCase() && data["to_address"] == SideBridge_address.toLocaleLowerCase() && !data["confirmed"]) {
67 const txlock = processReturnBurn(data);
68 const txbridge = processReturnUnlock(data);
69 }
70 else{
71 logger.info("transaction not related to bridge");
72 }
73 async function processReturnBurn(data) {
74 logger.info("returning tokens burning");
75 const functionCall = SideBridge.methods.returnTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
76 const gatewayNonce = web3Side.eth.getTransactionCount(gateway_address);
77 const transactionBody = {
78 to: SideBridge_address,
79 nonce:gatewayNonce,
80 data:functionCall,
81 gas:400000,
82 gasPrice:web3Side.utils.toWei("15", "gwei")
83 }
84 signedTransaction = await web3Side.eth.accounts.signTransaction(transactionBody,gatewayKey);
85 logger.info(signedTransaction.transactionHash);
86 fulfillTx = await web3Side.eth.sendSignedTransaction(signedTransaction.rawTransaction);
87 logger.info("fulfillTx: " + JSON.stringify(fulfillTx))
88 return fulfillTx;
89 }
90 async function processReturnUnlock(data) {
91 logger.info("returning starting unlocking tokens");
92 const functionCall = MainBridge.methods.unlockTokens(data["from_address"],data["value"],data["transaction_hash"]).encodeABI();
93 const gatewayNonce = web3Main.eth.getTransactionCount(gateway_address);
94 const transactionBody = {
95 to: MainBridge_address,
96 nonce:gatewayNonce,
97 data:functionCall,
98 gas:400000,
99 gasPrice:web3Main.utils.toWei("200", "gwei")
100 }
101 signedTransaction = await web3Main.eth.accounts.signTransaction(transactionBody,gatewayKey);
102 logger.info(signedTransaction.transactionHash);
103 fulfillTx = await web3Main.eth.sendSignedTransaction(signedTransaction.rawTransaction);
104 logger.info("fulfillTx: " + JSON.stringify(fulfillTx));
105 }
106});
The logger is reading the transactions then it appears to be trying to do something but it’s not actually executing them.
- 2022-09-06T15:10:40.720Z - transaction not related to bridge
- 2022-09-06T15:10:40.720Z - transaction not related to bridge
- 2022-09-06T15:10:40.720Z - undefined
- 2022-09-06T15:10:38.898Z - transaction not related to bridge
- 2022-09-06T15:10:38.897Z - undefined
- 2022-09-06T15:10:37.236Z - transaction not related to bridge
- 2022-09-06T15:10:37.234Z - undefined
- 2022-09-06T15:09:43.848Z - returning starting unlocking tokens
- 2022-09-06T15:09:43.827Z - returning tokens burning
- 2022-09-06T15:09:43.826Z - undefined