Skip to content

Commit a3eb8b9

Browse files
Merge pull request #6895 from BitGo/WIN-6321
feat: (skeleton) export tx builder for p chain
2 parents e045396 + 6a910fd commit a3eb8b9

File tree

3 files changed

+132
-4
lines changed

3 files changed

+132
-4
lines changed

modules/sdk-coin-flrp/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444
},
4545
"devDependencies": {
4646
"@types/bn.js": "^5.2.0",
47-
"@bitgo/sdk-test": "^9.0.5",
48-
"@bitgo/sdk-api": "^1.67.0"
47+
"@bitgo/sdk-test": "^9.0.9",
48+
"@bitgo/sdk-api": "^1.68.3"
4949
},
5050
"dependencies": {
51-
"@bitgo/sdk-core": "^36.5.0",
51+
"@bitgo/sdk-core": "^36.8.0",
5252
"@bitgo/secp256k1": "^1.5.0",
53-
"@bitgo/statics": "^57.5.0",
53+
"@bitgo/statics": "^57.8.0",
5454
"@flarenetwork/flarejs": "4.1.0-rc0",
5555
"@noble/curves": "1.8.1",
5656
"create-hash": "^1.2.0",
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { BaseCoin as CoinConfig } from '@bitgo/statics';
2+
import { BuildTransactionError, TransactionType } from '@bitgo/sdk-core';
3+
4+
/**
5+
* Minimal placeholder for Flare P-chain atomic transaction building.
6+
* This will be expanded with proper Flare P-chain logic (inputs/outputs/credentials, UTXO handling, fees, etc.).
7+
*/
8+
export abstract class AtomicTransactionBuilder {
9+
protected readonly _coinConfig: Readonly<CoinConfig>;
10+
// External chain id (destination) for export transactions
11+
protected _externalChainId: Buffer | undefined;
12+
13+
// Simplified internal transaction state (mirrors shape expected by existing builders)
14+
// Simplified internal transaction state
15+
protected transaction: {
16+
_network: Record<string, unknown>;
17+
_networkID: number;
18+
_blockchainID: Buffer;
19+
_assetId: Buffer;
20+
_fromAddresses: string[];
21+
_locktime: bigint;
22+
_threshold: number;
23+
fee: { fee: string };
24+
hasCredentials: boolean;
25+
_tx?: unknown;
26+
setTransaction: (tx: unknown) => void;
27+
} = {
28+
_network: {},
29+
_networkID: 0,
30+
_blockchainID: Buffer.alloc(0),
31+
_assetId: Buffer.alloc(0),
32+
_fromAddresses: [],
33+
_locktime: 0n,
34+
_threshold: 1,
35+
fee: { fee: '0' },
36+
hasCredentials: false,
37+
setTransaction: function (_tx: unknown) {
38+
this._tx = _tx;
39+
},
40+
};
41+
42+
constructor(coinConfig: Readonly<CoinConfig>) {
43+
this._coinConfig = coinConfig;
44+
}
45+
46+
protected abstract get transactionType(): TransactionType;
47+
48+
validateAmount(amount: bigint): void {
49+
if (amount <= 0n) {
50+
throw new BuildTransactionError('Amount must be positive');
51+
}
52+
}
53+
54+
/**
55+
* Placeholder that should assemble inputs/outputs and credentials once UTXO + key logic is implemented.
56+
*/
57+
protected createInputOutput(_total: bigint): { inputs: unknown[]; outputs: unknown[]; credentials: unknown[] } {
58+
return { inputs: [], outputs: [], credentials: [] };
59+
}
60+
61+
/**
62+
* Base initBuilder used by concrete builders. For now just returns this so fluent API works.
63+
*/
64+
initBuilder(_tx: unknown): this {
65+
return this;
66+
}
67+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { BaseCoin as CoinConfig } from '@bitgo/statics';
2+
import { TransactionType } from '@bitgo/sdk-core';
3+
import { AtomicTransactionBuilder } from './atomicTransactionBuilder';
4+
5+
export class ExportTxBuilder extends AtomicTransactionBuilder {
6+
private _amount = 0n;
7+
8+
constructor(_coinConfig: Readonly<CoinConfig>) {
9+
super(_coinConfig);
10+
}
11+
12+
protected get transactionType(): TransactionType {
13+
return TransactionType.Export;
14+
}
15+
16+
/**
17+
* Amount is a long that specifies the quantity of the asset that this output owns. Must be positive.
18+
*
19+
* @param {BN | string} amount The withdrawal amount
20+
*/
21+
amount(value: bigint | string | number): this {
22+
const v = typeof value === 'bigint' ? value : BigInt(value);
23+
this.validateAmount(v);
24+
this._amount = v;
25+
return this;
26+
}
27+
28+
/** @inheritdoc */
29+
// Placeholder: parsing existing ExportTx not yet supported on Flare P-chain
30+
initBuilder(_tx: unknown): this {
31+
super.initBuilder(_tx);
32+
return this;
33+
}
34+
35+
// Type verification not yet implemented for Flare P-chain
36+
static verifyTxType(_baseTx: unknown): boolean {
37+
return false;
38+
}
39+
40+
verifyTxType(_baseTx: unknown): boolean {
41+
return ExportTxBuilder.verifyTxType(_baseTx);
42+
}
43+
44+
/**
45+
* Create the internal transaction.
46+
* @protected
47+
*/
48+
// Build not implemented yet
49+
protected buildFlareTransaction(): void {
50+
throw new Error('Flare P-chain export transaction build not implemented');
51+
}
52+
53+
/**
54+
* Create the ExportedOut where the recipient address are the sender.
55+
* Later a importTx should complete the operations signing with the same keys.
56+
* @protected
57+
*/
58+
protected exportedOutputs(): unknown[] {
59+
return [];
60+
}
61+
}

0 commit comments

Comments
 (0)