Skip to content

Commit

Permalink
refactor(sdk-coin-icp): introduce NetworkID enum and enhance transact…
Browse files Browse the repository at this point in the history
…ion serialization with SignedTransactionRequest

TICKET: WIN-4641
  • Loading branch information
mohd-kashif committed Feb 25, 2025
1 parent 2cfa84e commit f2ddea0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
14 changes: 14 additions & 0 deletions modules/sdk-coin-icp/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export enum MethodName {
SEND_PB = 'send_pb', // send_pb is the method name for ICP transfer transaction
}

export enum NetworkID {
MAINNET = '00000000000000020101', // ICP does not have different network IDs for mainnet and testnet
}

export interface IcpTransactionData {
senderAddress: string;
receiverAddress: string;
Expand Down Expand Up @@ -170,3 +174,13 @@ export interface IcpTransactionExplanation extends BaseTransactionExplanation {
sender?: string;
type?: BitGoTransactionType;
}

export interface NetworkIdentifier {
blockchain: string;
network: string;
}

export interface SignedTransactionRequest {
network_identifier: NetworkIdentifier;
signed_transaction: string;
}
20 changes: 18 additions & 2 deletions modules/sdk-coin-icp/src/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
Signatures,
TxData,
IcpTransactionExplanation,
SignedTransactionRequest,
NetworkID,
} from './iface';
import { Utils } from './utils';
import { KeyPair } from './keyPair';
Expand Down Expand Up @@ -167,8 +169,22 @@ export class Transaction extends BaseTransaction {
}

/** @inheritdoc */
toBroadcastFormat(): void {
throw new Error('Method not implemented.');
toBroadcastFormat(): string {
if (!this._signedTransaction) {
throw new InvalidTransactionError('Empty transaction');
}
return this.serialize();
}

serialize(): string {
const transaction: SignedTransactionRequest = {
signed_transaction: this._signedTransaction,
network_identifier: {
blockchain: this._coinConfig.fullName,
network: NetworkID.MAINNET,
},
};
return Buffer.from(JSON.stringify(transaction)).toString('base64');
}

/** @inheritdoc */
Expand Down

0 comments on commit f2ddea0

Please sign in to comment.