Skip to content

Commit

Permalink
fix coin control
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCyjaneK committed Oct 25, 2024
1 parent 14b348b commit 1079275
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
4 changes: 4 additions & 0 deletions impls/monero.ts/src/coinsInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class CoinsInfo {
return await readCString(await getSymbol("CoinsInfo_hash")(this.#coinsInfoPtr));
}

async keyImage(): Promise<string | null> {
return await readCString(await getSymbol("CoinsInfo_keyImage")(this.#coinsInfoPtr));
}

async blockHeight(): Promise<bigint> {
return await getSymbol("CoinsInfo_blockHeight")(this.#coinsInfoPtr);
}
Expand Down
7 changes: 7 additions & 0 deletions impls/monero.ts/src/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ export const moneroSymbols = {
// const char*
result: "pointer",
},
"MONERO_CoinsInfo_keyImage": {
nonblocking: true,
// void* coinsInfo_ptr
parameters: ["pointer"],
// const char*
result: "pointer",
},
"MONERO_CoinsInfo_blockHeight": {
nonblocking: true,
// void* coinsInfo_ptr
Expand Down
13 changes: 13 additions & 0 deletions impls/monero.ts/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class Wallet {

async initWallet(daemonAddress: string): Promise<void> {
await this.init(daemonAddress);
// await this.init3(); - enable logging to console
await this.setTrustedDaemon(true);
await this.setDaemonAddress(daemonAddress);
await this.startRefresh();
Expand Down Expand Up @@ -98,6 +99,18 @@ export class Wallet {
return bool;
}

async init3(): Promise<void> {
// void* wallet_ptr, const char* argv0, const char* default_log_base_name,
// const char* log_path, bool console
const bool = await getSymbol("Wallet_init3")(
this.#walletPtr,
CString(""),
CString(""),
CString(""),
true,
);
}

async setTrustedDaemon(value: boolean): Promise<void> {
await getSymbol("Wallet_setTrustedDaemon")(this.#walletPtr, value);
}
Expand Down
17 changes: 9 additions & 8 deletions tests/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ Deno.test("0001-polyseed.patch", async (t) => {
walletInfo.offset,
);

await wallet.initWallet(NODE_URL);
await wallet.initWallet(""); // empty string for offline test

assertEquals(await wallet.address(), walletInfo.address);

Expand Down Expand Up @@ -269,7 +269,7 @@ Deno.test("0002-wallet-background-sync-with-just-the-view-key.patch", async () =
const interval = setInterval(async () => {
const blockChainHeight = BigInt(await backgroundWallet.blockChainHeight());
const daemonBlockchainHeight = BigInt(await backgroundWallet.daemonBlockChainHeight());
console.log("Blockchain height:", blockChainHeight, "Daemon blockchain height:", daemonBlockchainHeight);
console.log("Blockchain height:", blockChainHeight, "Daemon blockchain height:", daemonBlockchainHeight, "Remains:", daemonBlockchainHeight-blockChainHeight);

if (blockChainHeight === daemonBlockchainHeight) {
clearInterval(interval);
Expand Down Expand Up @@ -328,7 +328,7 @@ Deno.test("0004-coin-control.patch", {
const interval = setInterval(async () => {
const blockChainHeight = BigInt(await wallet.blockChainHeight());
const daemonBlockchainHeight = BigInt(await wallet.daemonBlockChainHeight());
console.log("Blockchain height:", blockChainHeight, "Daemon blockchain height:", daemonBlockchainHeight);
console.log("Blockchain height:", blockChainHeight, "Daemon blockchain height:", daemonBlockchainHeight, "Remains:", daemonBlockchainHeight-blockChainHeight);

if (blockChainHeight === daemonBlockchainHeight) {
clearInterval(interval);
Expand All @@ -355,7 +355,7 @@ Deno.test("0004-coin-control.patch", {
const availableCoinsData: Record<string, {
index: number;
coin: CoinsInfo;
hash: string | null;
keyImage: string | null;
amount: bigint;
}[]> = {
["0.001"]: [],
Expand Down Expand Up @@ -401,7 +401,7 @@ Deno.test("0004-coin-control.patch", {
availableCoinsData[humanReadableAmount].push({
index: i,
coin,
hash: await coin.hash(),
keyImage: await coin.keyImage(),
amount,
});

Expand All @@ -422,7 +422,7 @@ Deno.test("0004-coin-control.patch", {
0,
0,
false,
availableCoinsData["0.001"][0].hash!,
availableCoinsData["0.001"][0].keyImage!,
);
assertEquals(await transaction.status(), 1);
});
Expand All @@ -443,15 +443,16 @@ Deno.test("0004-coin-control.patch", {
await freezeAll();
await coins.thaw(availableCoinsData["0.001"][0].index);
await coins.thaw(availableCoinsData["0.001"][1].index);

console.log("a");
const transaction = await wallet.createTransaction(
DESTINATION_ADDRESS,
2n * BILLION,
0,
0,
false,
availableCoinsData["0.001"][0].hash!,
availableCoinsData["0.001"][0].keyImage!,
);
console.log("b");

assertEquals(await transaction.status(), 1);
assertEquals(
Expand Down

0 comments on commit 1079275

Please sign in to comment.