XO wallet integration

This commit is contained in:
Jim Hamill
2025-05-05 03:19:47 +00:00
parent f9fe792542
commit e0a554e897
14 changed files with 745 additions and 213 deletions
+31 -30
View File
@@ -46,20 +46,27 @@ export type WalletP2PKHGenesisData = {
export class WalletP2PKH extends BaseWallet {
static async from<T extends typeof WalletP2PKH>(
this: T,
dependencies: WalletDependencies,
deps: WalletDependencies,
genesisData: WalletP2PKHGenesisData,
) {
// Assign in memory stores as defaults in case otherwise not provided.
const dependenciesFinal = {
...{
activities: await Activities.fromStores(StoreInMemory.from()),
cache: new StoreInMemory(),
},
...dependencies,
// Assign defaults if not otherwise provideed.
const activities = deps.activities
? deps.activities
: await Activities.from();
const cache = deps.cache ? deps.cache : StoreInMemory.from();
// Assign our final dependencies.
const depsFinal = {
activities,
cache,
blockchain: deps.blockchain,
};
// Return a new instance of Wallet P2PKH.
return new this(dependenciesFinal, genesisData) as InstanceType<T>;
const wallet = new this(depsFinal, genesisData) as InstanceType<T>;
// Return the wallet instance.
return wallet;
}
static fromBytes<T extends typeof WalletP2PKH>(
@@ -188,10 +195,6 @@ export class WalletP2PKH extends BaseWallet {
);
}
async getActivities(): Promise<Activities> {
return this.activities;
}
async start() {
// Do nothing if already started.
if (this.isStarted) {
@@ -314,23 +317,21 @@ export class WalletP2PKH extends BaseWallet {
const compilerP2PKH = walletTemplateToCompilerBCH(walletTemplateP2pkhNonHd);
// Transform our inputs into unlocking directives.
const inputDirectives = unspentOutputs
.map((blockchainUTXO) => ({
outpointIndex: blockchainUTXO.utxo.outpoint.outpointIndex,
outpointTransactionHash:
blockchainUTXO.utxo.outpoint.outpointTransactionHash,
sequenceNumber: 0,
unlockingBytecode: {
compiler: compilerP2PKH,
data: {
keys: { privateKeys: { key: this.privateKey.toBytes() } },
},
script: 'unlock',
token: blockchainUTXO.utxo.output.token,
valueSatoshis: blockchainUTXO.utxo.output.valueSatoshis,
const inputDirectives = unspentOutputs.map((blockchainUTXO) => ({
outpointIndex: blockchainUTXO.utxo.outpoint.outpointIndex,
outpointTransactionHash:
blockchainUTXO.utxo.outpoint.outpointTransactionHash,
sequenceNumber: 0,
unlockingBytecode: {
compiler: compilerP2PKH,
data: {
keys: { privateKeys: { key: this.privateKey.toBytes() } },
},
}))
.toArray();
script: 'unlock',
token: blockchainUTXO.utxo.output.token,
valueSatoshis: blockchainUTXO.utxo.output.valueSatoshis,
},
}));
// Return the directives.
return inputDirectives;
@@ -397,7 +398,7 @@ export class WalletP2PKH extends BaseWallet {
// Build the transaction.
const tx = TransactionBuilder.build(
txTemplateFinal,
unspents,
unspents.toArray(),
changeLockingBytecode,
);