Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ export function ensureHexPrefix(hexString: string): string {
}

return hexString;
}
}

export function ensureHexLength(hex: string, bytes: number): string {
// Remove 0x prefix if present
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
// Pad to desired byte length (bytes → hex chars = bytes * 2)
return "0x" + cleanHex.padStart(bytes * 2, "0");
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HTLCBlockEventResponse, HTLCCommitEventMessage, HTLCLockEventMessage }
import { DetailedNetworkDto } from "../../../Blockchain.Abstraction/Models/DetailedNetworkDto";
import { FormatAddress } from "../FuelBlockchainActivities";
import { TokenCommittedEvent, TokenLockedEvent } from "../Models/EventModels";
import { ensureHexLength } from "../../../Blockchain.Abstraction/Extensions/StringExtensions";

export default async function TrackBlockEventsAsync(
network: DetailedNetworkDto,
Expand Down Expand Up @@ -159,11 +160,4 @@ export default async function TrackBlockEventsAsync(

throw error;
}
}

function ensureHexLength(hex: string, bytes: number): string {
// Remove 0x prefix if present
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
// Pad to desired byte length (bytes → hex chars = bytes * 2)
return "0x" + cleanHex.padStart(bytes * 2, "0");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CallData, hash, num, Provider, events } from "starknet";
import trainAbi from '../ABIs/Train.json';
import { formatAddress } from "../StarknetBlockchainActivities";
import { HTLCBlockEventResponse, HTLCCommitEventMessage, HTLCLockEventMessage } from "../../../Blockchain.Abstraction/Models/EventModels/HTLCBlockEventResposne";
import { BigIntToAscii, ensureHexPrefix, toHex } from "../../../Blockchain.Abstraction/Extensions/StringExtensions";
import { BigIntToAscii, ensureHexLength, ensureHexPrefix, toHex } from "../../../Blockchain.Abstraction/Extensions/StringExtensions";
import { DetailedNetworkDto } from "../../../Blockchain.Abstraction/Models/DetailedNetworkDto";
import { TokenCommittedEvent, TokenLockedEvent } from "../../Models/EventModels";

Expand Down Expand Up @@ -58,11 +58,12 @@ export async function TrackBlockEventsAsync(

const logEvent = rawEvents.find(x => x.transaction_hash === parsed.transaction_hash);

const dstAddress = ensureHexPrefix(logEvent.data[8]);

const dstAddress = ensureHexPrefix(logEvent.data[8]);
const commitId = ensureHexLength(toHex(data.Id), 32);

const commitMsg: HTLCCommitEventMessage = {
txId: parsed.transaction_hash,
commitId: toHex(data.Id),
commitId: commitId,
amount: Number(data.amount).toString(),
receiverAddress: receiverAddress,
sourceNetwork: network.name,
Expand All @@ -79,10 +80,13 @@ export async function TrackBlockEventsAsync(
else if (eventName.endsWith("TokenLockAdded")) {
const data = eventData as unknown as TokenLockedEvent;

const commitId = ensureHexLength(toHex(data.Id), 32);
const hashlock = ensureHexLength(toHex(data.hashlock), 32);

const lockMsg: HTLCLockEventMessage = {
txId: parsed.transaction_hash,
commitId: toHex(data.Id),
hashLock: toHex(data.hashlock),
commitId: commitId,
hashLock: hashlock,
timeLock: Number(data.timelock),
};

Expand Down