Skip to content

Commit

Permalink
fix: updated logic for handling submitter address
Browse files Browse the repository at this point in the history
  • Loading branch information
frazarshad committed Jun 13, 2024
1 parent 2ed2579 commit fb833ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getStateChangeModule,
resolveBrandNamesAndValues,
getEscrowAddress,
getAddressFromUint8Array,
} from './utils';

import {
Expand Down Expand Up @@ -137,15 +138,15 @@ export async function handleBundleInstallMessage(message: CosmosMessage): Promis
}

// JSON.stringify converts the object from Uint8Array to readable string
const { uncompressedSize, compressedBundle, submitter, bundle } = JSON.parse(JSON.stringify(msg.decodedMsg));
const { uncompressedSize, compressedBundle, bundle } = JSON.parse(JSON.stringify(msg.decodedMsg));
const bundleRecord = new BundleInstall(
tx.hash,
BigInt(block.header.height),
block.header.time as any,
BigInt(uncompressedSize),
bundle || '',
compressedBundle || '',
submitter,
getAddressFromUint8Array(msg.decodedMsg.submitter),
);

await bundleRecord.save();
Expand Down
11 changes: 8 additions & 3 deletions src/mappings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,15 @@ export function dateToDayKey(timestamp: any): number {

export const getEscrowAddress = (port: string, channel: string) => {
const version = 'ics20-1';
const chainPrefix = 'agoric';
const stringtoSha = Buffer.from([...Buffer.from(version), 0, ...Buffer.from(`${port}/${channel}`)]);
const shaHash = sha256.sha256.array(stringtoSha.toString());
const bechWords = bech32.toWords(shaHash.slice(0, 20));
const address = bech32.encode(chainPrefix, bechWords);
const address = getAddressFromUint8Array(shaHash.slice(0, 20));
return address;
};

export const getAddressFromUint8Array = (uint8Array: Array<number>, chainPrefix: string = 'agoric') => {
const words = bech32.toWords(uint8Array);
const bech32String = bech32.encode(chainPrefix, words);

return bech32String;
};

0 comments on commit fb833ea

Please sign in to comment.