-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(hapi-evm): adapt apply function to listen for outgoing native to…
…ken transfers
- Loading branch information
1 parent
d846cb3
commit 9c78403
Showing
10 changed files
with
136 additions
and
73 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# global | ||
STAGE=dev | ||
APP_NAME=eosio-dashboard | ||
APP_NAME=antelope-tools | ||
|
||
# wallet | ||
WALLET_DATA=./wallet_data | ||
|
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# global | ||
STAGE=dev | ||
APP_NAME=eosio-dashboard | ||
APP_NAME=antelope-tools | ||
|
||
# wallet | ||
WALLET_DATA=./wallet_data | ||
|
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
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
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
92 changes: 67 additions & 25 deletions
92
hapi-evm/src/services/hyperion/updaters/eosio-evm-transfer.updater.ts
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 |
---|---|---|
@@ -1,32 +1,74 @@ | ||
import { transferModel } from '../../../models' | ||
|
||
// TODO: handle this as a network function, for example, base on the | ||
// network config, the action type and logic will be different | ||
import { networkConfig } from '../../../config' | ||
import { transferModel, defaultModel } from '../../../models' | ||
|
||
// TODO: move this to env | ||
const defaultMemo = 'Withdraw balance for' | ||
|
||
export default { | ||
type: `eosio.evm:withdraw`, | ||
notified_account: `eosio.evm`, | ||
apply: async (action: any) => { | ||
const [amount, symbol] = action.data.quantity.split(' ') | ||
|
||
try { | ||
await transferModel.queries.save({ | ||
block: action.block, | ||
transaction_id: action.transaction_id, | ||
timestamp: action.timestamp, | ||
from: 'eosio.evm', | ||
to: action.data.to, | ||
amount: amount, | ||
symbol: symbol, | ||
memo: `${defaultMemo}: ${action.data.to}`, | ||
quantity: action.data.quantity, | ||
type: transferModel.interfaces.Type.outgoing | ||
}) | ||
} catch (error: any) { | ||
console.error(`error to sync ${action.action}: ${error.message}`) | ||
const applyEosio = async (action: any) => { | ||
if (action.data.from !== 'eosio.evm') return | ||
|
||
try { | ||
await transferModel.queries.save({ | ||
block: action.block, | ||
transaction_id: action.transaction_id, | ||
timestamp: action.timestamp, | ||
from: action.data.from, | ||
to: action.data.to, | ||
amount: action.data.amount, | ||
symbol: action.data.symbol, | ||
memo: action.data.memo, | ||
quantity: action.data.quantity, | ||
type: transferModel.interfaces.Type.outgoing | ||
}) | ||
} catch (error: any) { | ||
console.error(`error to sync ${action.action}: ${error.message}`) | ||
} | ||
} | ||
|
||
const applyTelos = async (action: any) => { | ||
const [amount, symbol] = action.data.quantity.split(' ') | ||
|
||
try { | ||
await transferModel.queries.save({ | ||
block: action.block, | ||
transaction_id: action.transaction_id, | ||
timestamp: action.timestamp, | ||
from: 'eosio.evm', | ||
to: action.data.to, | ||
amount: amount, | ||
symbol: symbol, | ||
memo: `${defaultMemo}: ${action.data.to}`, | ||
quantity: action.data.quantity, | ||
type: transferModel.interfaces.Type.outgoing | ||
}) | ||
} catch (error: any) { | ||
console.error(`error to sync ${action.action}: ${error.message}`) | ||
} | ||
} | ||
|
||
const build = ( | ||
network: defaultModel.AllowedNetworkType = defaultModel.AllowedNetwork.EOSIO | ||
): defaultModel.BuilderListener => { | ||
const listener = { | ||
[defaultModel.AllowedNetwork.EOSIO]: { | ||
type: `eosio.token:transfer,act.data.from=eosio.evm`, | ||
notified_account: `eosio.evm`, | ||
apply: applyEosio | ||
}, | ||
[defaultModel.AllowedNetwork.TELOS]: { | ||
type: `eosio.evm:withdraw`, | ||
notified_account: `eosio.evm`, | ||
apply: applyTelos | ||
} | ||
} | ||
|
||
const selectedNetworkListener = listener[network] | ||
|
||
if (!selectedNetworkListener) { | ||
throw new Error(`network ${network} not supported`) | ||
} | ||
|
||
return selectedNetworkListener | ||
} | ||
|
||
export default build(networkConfig.network) |