Skip to content

Commit

Permalink
fix the staking event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
D4mph1r committed Aug 6, 2024
1 parent a5c3268 commit cd8d102
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 29 deletions.
60 changes: 60 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

call_lefthook()
{
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"

elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
fi
}

call_lefthook run "pre-commit" "$@"
60 changes: 60 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

call_lefthook()
{
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"

elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
fi
}

call_lefthook run "prepare-commit-msg" "$@"
30 changes: 20 additions & 10 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ export const prodBridgeConfig: IBridgeConfig = {
bridgeChains: [
{
chain: "BSC",
rpcURL: "https://bsc-pokt.nodies.app",
rpcURL: "https://bsc.blockpi.network/v1/rpc/public",
nativeCoinSymbol: "BNB",
intialFund: "50000000000000000",
contractAddress: "0x0E8457f9F2a323DD91673e2D8e9eCA80763Dd98f",
contractAddress: "0x9ED1D37E27561fD416bec704402DA5295084deff",
chainType: "evm",
lastBlock: 40722598,
lastBlock: 41099482,
decimals: 18,
blockChunks: 1000,
},
Expand All @@ -113,7 +113,7 @@ export const prodBridgeConfig: IBridgeConfig = {
rpcURL: "https://polygon-pokt.nodies.app",
nativeCoinSymbol: "MATIC",
intialFund: "50000000000000000",
contractAddress: "0xDAc202538A33adC727e95768f472f232eDD2EC56",
contractAddress: "0x12E614A372510cb3bcB75a12d11e7760dE534ed0",
chainType: "evm",
lastBlock: 59709068,
decimals: 18,
Expand All @@ -124,35 +124,45 @@ export const prodBridgeConfig: IBridgeConfig = {
rpcURL: "https://mainnet.hashio.io/api",
nativeCoinSymbol: "HBAR",
intialFund: "50000000000000000000",
contractAddress: "0xdb3ae6531d405d341d7b25597a64082d7ed05a07",
contractAddress: "0x0000000000000000000000000000000000648929",
chainType: "hedera",
lastBlock: 66851249,
royaltyInfoProxyAddress: "0x97fec8ed7203ea3ce58e2a4f44056fd954a35be4",
decimals: 18,
blockChunks: 1000,
},
{
chain: "TON",
rpcURL: "https://toncenter.com/api/v2/jsonRPC",
chainType: "ton",
contractAddress: "EQBuZspBrrEBIs7NYTkJ2A1lESRZupvU63rMkdyKZeSZaJNI",
decimals: 9,
intialFund: "100000000",
lastBlock: 24014875000001,
nativeCoinSymbol: "TON",
},
],
storageConfig: {
chain: "OP",
rpcURL: "https://optimism-mainnet.public.blastapi.io",
nativeCoinSymbol: "OP",
intialFund: "5000000000000000",
contractAddress: "0xA8802be1Bd39888EBD38b236e2A4fAd4d8e76a1d",
contractAddress: "0x2Aa8Dbb7543754d70B5A40D52cB81c2a0bB08B83",
chainType: "evm",
lastBlock: 122850904,
lastBlock: 123638429,
decimals: 18,
blockChunks: 1000,
},
stakingConfig: {
chain: "BSC",
rpcURL: "https://bsc-pokt.nodies.app",
rpcURL: "https://bsc.blockpi.network/v1/rpc/public",
coinSymbol: "XPNET",
nativeCoinSymbol: "BNB",
chainType: "evm",
coinAddress: "0x8cf8238abf7b933Bf8BB5Ea2C7E4Be101c11de2A",
contractAddress: "0xDbA9bC0F6c9a59334Fb1e1dc4E50f0E21aAB3Ac7",
contractAddress: "0xD7f7aa3e438B5640caDe99070336093833e19448",
intialFund: "0",
lastBlock: 40722598,
lastBlock: 41099482,
decimals: 18,
blockChunks: 1000,
},
Expand Down
6 changes: 2 additions & 4 deletions src/handler/evm/utils/listenForStakingEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ const listenForStakingEvents = (
const startBlock = lastBlock;

if (!logs.length) {
logger.trace(
`${startBlock} -> ${latestBlockNumber}: 0 TXs. Awaiting 10s`,
);
lastBlock = latestBlockNumber;
logger.trace(`${startBlock} -> ${latestBlock}: 0 TXs. Awaiting 10s`);
lastBlock = latestBlock;
await em.upsert(Block, {
chain: chainIdent,
contractAddress: staker,
Expand Down
15 changes: 0 additions & 15 deletions src/handler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,6 @@ export async function listenStakeEvents(
}[] = [];

for (const sig of ev) {
const validatorEpoch = await deps.storage.validatorEpoch(
sig.validatorAddress,
);

const alreadyVoted = await deps.storage.validatorVoted(
sig.validatorAddress,
currentValidatorAddress,
validatorEpoch,
);
if (alreadyVoted) {
log.info(
`Already voted for ${sig.validatorAddress} - ${sig.chainType}`,
);
continue;
}
const dc = map.get(sig.chainType);
if (!dc) {
throw new Error(`Unknown destination chain type: ${sig.chainType}`);
Expand Down

0 comments on commit cd8d102

Please sign in to comment.