Skip to content

Commit

Permalink
chore: remove encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed Dec 13, 2024
1 parent 57d335d commit aea3527
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
retries: 5

subquery-node:
image: subquerynetwork/subql-node-cosmos:v3.12.0
image: subquerynetwork/subql-node-cosmos:v4.2.1
depends_on:
'postgres':
condition: service_healthy
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"@cosmjs/stargate": "^0.28.9",
"@subql/cli": "^5.4.0",
"@subql/node-cosmos": "^4.2.1",
"@subql/node-cosmos": "4.2.1",
"@subql/testing": "latest",
"prettier": "^3.4.2",
"starknet": "6.11.0",
Expand Down
16 changes: 8 additions & 8 deletions src/mappings/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { b64encode } from './utils';
import {} from './utils';

export const EVENT_TYPES = {
ACTIVE_PROPOSAL: 'active_proposal',
Expand Down Expand Up @@ -43,11 +43,11 @@ export const PACKET_SRC_CHANNEL_KEY = 'packet_src_channel';
export const PACKET_DST_CHANNEL_KEY = 'packet_dst_channel';
export const PACKET_SRC_PORT_KEY = 'packet_src_port';
export const PACKET_DST_PORT_KEY = 'packet_dst_port';
export const ACTION_KEY = b64encode('action');
export const IBC_MESSAGE_TRANSFER_VALUE = b64encode('/ibc.applications.transfer.v1.MsgTransfer');
export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = b64encode('/ibc.core.channel.v1.MsgRecvPacket');
export const RECEPIENT_KEY = b64encode('recipient');
export const SENDER_KEY = b64encode('sender');
export const RECEIVER_KEY = b64encode('receiver');
export const AMOUNT_KEY = b64encode('amount');
export const ACTION_KEY = 'action';
export const IBC_MESSAGE_TRANSFER_VALUE = '/ibc.applications.transfer.v1.MsgTransfer';
export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = '/ibc.core.channel.v1.MsgRecvPacket';
export const RECEPIENT_KEY = 'recipient';
export const SENDER_KEY = 'sender';
export const RECEIVER_KEY = 'receiver';
export const AMOUNT_KEY = 'amount';
export const TRANSFER_PORT_VALUE = 'transfer';
3 changes: 0 additions & 3 deletions src/mappings/events/vaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ export const vaultsEventKit = (block: any, data: any, module: string, path: stri
}

async function saveWallets(payload: any): Promise<Promise<any>[]> {
logger.info(`PAYLOAD: ${JSON.stringify(payload)}`);
const promises: Promise<void>[] = [];
const address = path.split('.')[2];
logger.info(`WALLET PATH: ${path}`);
logger.info(`time: ${block.block.header.time as any}`);
const wallet = new Wallet(path, BigInt(data.blockHeight), block.block.header.time as any, address);

if (payload.offerToPublicSubscriberPaths) {
Expand Down
12 changes: 2 additions & 10 deletions src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,6 @@ export async function handleBundleInstallMessage(message: CosmosMessage): Promis
export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise<void> {
const { event, block } = cosmosEvent as CosmosEvent & { event: tendermint37.Event };

logger.info(`EVENT ${JSON.stringify(event)}`);
logger.info(`EVENT TYPE:${event.type}`);

if (event.type != EVENT_TYPES.STATE_CHANGE) {
logger.warn('Not valid state_change event.');
return;
Expand All @@ -176,16 +173,14 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise<
}

const keyAttr = event.attributes.find((a) => a.key === KEY_KEY || a.key === SUBKEY_KEY);

if (!keyAttr) {
logger.warn('Key attribute is missing or empty.');
return;
}

let data = Object();
try {
const decodedValue = valueAttr.key === UNPROVED_VALUE_KEY ? valueAttr.value : valueAttr.value;

const decodedValue = valueAttr.key === UNPROVED_VALUE_KEY ? b64decode(valueAttr.value) : valueAttr.value;
data = JSON.parse(decodedValue);
} catch (e) {
return;
Expand All @@ -196,15 +191,13 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise<
return;
}

const decodedKey = keyAttr.key === SUBKEY_KEY ? keyAttr.value.replaceAll('\u0000', '\x00') : keyAttr.value;
const decodedKey = keyAttr.key === SUBKEY_KEY ? b64decode(keyAttr.value).replaceAll('\u0000', '\x00') : keyAttr.value;
const path = extractStoragePath(decodedKey);
const module = getStateChangeModule(path);

const recordSaves: (Promise<void> | undefined)[] = [];

async function saveStateEvent(idx: number, value: any, payload: any) {
logger.info(`ID: ${data.blockHeight}:${cosmosEvent.idx}:${idx}`);

const record = new StateChangeEvent(
`${data.blockHeight}:${cosmosEvent.idx}:${idx}`,
BigInt(data.blockHeight),
Expand All @@ -217,7 +210,6 @@ export async function handleStateChangeEvent(cosmosEvent: CosmosEvent): Promise<
);

recordSaves.push(record.save());
logger.info('RECORD SAVED');
}

const psmKit = psmEventKit(block, data, module, path);
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3305,7 +3305,7 @@ __metadata:
languageName: node
linkType: hard

"@subql/node-cosmos@npm:^4.2.1":
"@subql/node-cosmos@npm:4.2.1":
version: 4.2.1
resolution: "@subql/node-cosmos@npm:4.2.1"
dependencies:
Expand Down Expand Up @@ -4107,7 +4107,7 @@ __metadata:
dependencies:
"@cosmjs/stargate": "npm:^0.28.9"
"@subql/cli": "npm:^5.4.0"
"@subql/node-cosmos": "npm:^4.2.1"
"@subql/node-cosmos": "npm:4.2.1"
"@subql/testing": "npm:latest"
"@subql/types-cosmos": "npm:^4.0.0"
"@subql/utils": "npm:^2.17.0"
Expand Down

0 comments on commit aea3527

Please sign in to comment.