|
1 | 1 | import { Account } from "./account.js";
|
2 | 2 | import { AleoNetworkClient, AleoNetworkClientOptions, ProgramImports } from "./network-client.js";
|
3 | 3 | import { ImportedPrograms, ImportedVerifyingKeys } from "./models/imports.js";
|
4 |
| -import { RecordProvider, RecordSearchParams } from "./record-provider.js"; |
| 4 | +import { RecordProvider } from "./record-provider.js"; |
| 5 | +import { RecordSearchParams } from "./models/record-provider/recordSearchParams.js"; |
5 | 6 |
|
6 | 7 | import {
|
7 | 8 | AleoKeyProvider,
|
@@ -35,6 +36,7 @@ import {
|
35 | 36 | } from "./constants.js";
|
36 | 37 |
|
37 | 38 | import { logAndThrow } from "./utils.js";
|
| 39 | +import { OwnedRecord } from "./models/record-provider/ownedRecord.js"; |
38 | 40 |
|
39 | 41 | /**
|
40 | 42 | * Represents the options for executing a transaction in the Aleo network.
|
@@ -350,14 +352,12 @@ class ProgramManager {
|
350 | 352 | // Get the fee record from the account if it is not provided in the parameters
|
351 | 353 | try {
|
352 | 354 | feeRecord = privateFee
|
353 |
| - ? <RecordPlaintext>( |
354 |
| - await this.getCreditsRecord( |
| 355 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
355 | 356 | priorityFee,
|
356 | 357 | [],
|
357 | 358 | feeRecord,
|
358 | 359 | recordSearchParams,
|
359 |
| - ) |
360 |
| - ) |
| 360 | + )).recordPlaintext?? '') |
361 | 361 | : undefined;
|
362 | 362 | } catch (e: any) {
|
363 | 363 | logAndThrow(
|
@@ -564,14 +564,12 @@ class ProgramManager {
|
564 | 564 | // Get the fee record from the account if it is not provided in the parameters
|
565 | 565 | try {
|
566 | 566 | feeRecord = privateFee
|
567 |
| - ? <RecordPlaintext>( |
568 |
| - await this.getCreditsRecord( |
| 567 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
569 | 568 | priorityFee,
|
570 | 569 | [],
|
571 | 570 | feeRecord,
|
572 | 571 | recordSearchParams,
|
573 |
| - ) |
574 |
| - ) |
| 572 | + )).recordPlaintext?? '') |
575 | 573 | : undefined;
|
576 | 574 | } catch (e: any) {
|
577 | 575 | logAndThrow(
|
@@ -909,14 +907,12 @@ class ProgramManager {
|
909 | 907 | // Get the fee record from the account if it is not provided in the parameters.
|
910 | 908 | try {
|
911 | 909 | feeRecord = privateFee
|
912 |
| - ? <RecordPlaintext>( |
913 |
| - await this.getCreditsRecord( |
| 910 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
914 | 911 | priorityFee,
|
915 | 912 | [],
|
916 | 913 | feeRecord,
|
917 | 914 | recordSearchParams,
|
918 |
| - ) |
919 |
| - ) |
| 915 | + )).recordPlaintext?? '') |
920 | 916 | : undefined;
|
921 | 917 | } catch (e: any) {
|
922 | 918 | logAndThrow(
|
@@ -1244,14 +1240,12 @@ class ProgramManager {
|
1244 | 1240 | // Get the fee record from the account if it is not provided in the parameters
|
1245 | 1241 | try {
|
1246 | 1242 | feeRecord = privateFee
|
1247 |
| - ? <RecordPlaintext>( |
1248 |
| - await this.getCreditsRecord( |
| 1243 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
1249 | 1244 | priorityFee,
|
1250 | 1245 | [],
|
1251 | 1246 | feeRecord,
|
1252 | 1247 | recordSearchParams,
|
1253 |
| - ) |
1254 |
| - ) |
| 1248 | + )).recordPlaintext?? '') |
1255 | 1249 | : undefined;
|
1256 | 1250 | } catch (e: any) {
|
1257 | 1251 | logAndThrow(
|
@@ -1517,27 +1511,23 @@ class ProgramManager {
|
1517 | 1511 | const nonces: string[] = [];
|
1518 | 1512 | if (requiresAmountRecord(transferType)) {
|
1519 | 1513 | // If the transfer type is private and requires an amount record, get it from the record provider
|
1520 |
| - amountRecord = <RecordPlaintext>( |
1521 |
| - await this.getCreditsRecord( |
| 1514 | + amountRecord = RecordPlaintext.fromString((await this.getCreditsRecord( |
1522 | 1515 | priorityFee,
|
1523 | 1516 | [],
|
1524 | 1517 | amountRecord,
|
1525 | 1518 | recordSearchParams,
|
1526 |
| - ) |
1527 |
| - ); |
| 1519 | + )).recordPlaintext?? ''); |
1528 | 1520 | nonces.push(amountRecord.nonce());
|
1529 | 1521 | } else {
|
1530 | 1522 | amountRecord = undefined;
|
1531 | 1523 | }
|
1532 | 1524 | feeRecord = privateFee
|
1533 |
| - ? <RecordPlaintext>( |
1534 |
| - await this.getCreditsRecord( |
| 1525 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
1535 | 1526 | priorityFee,
|
1536 | 1527 | nonces,
|
1537 | 1528 | feeRecord,
|
1538 | 1529 | recordSearchParams,
|
1539 |
| - ) |
1540 |
| - ) |
| 1530 | + )).recordPlaintext?? '') |
1541 | 1531 | : undefined;
|
1542 | 1532 | } catch (e: any) {
|
1543 | 1533 | logAndThrow(
|
@@ -2504,21 +2494,25 @@ class ProgramManager {
|
2504 | 2494 | nonces: string[],
|
2505 | 2495 | record?: RecordPlaintext | string,
|
2506 | 2496 | params?: RecordSearchParams,
|
2507 |
| - ): Promise<RecordPlaintext> { |
| 2497 | + ): Promise<OwnedRecord> { |
2508 | 2498 | try {
|
2509 |
| - return record instanceof RecordPlaintext |
2510 |
| - ? record |
2511 |
| - : RecordPlaintext.fromString(<string>record); |
| 2499 | + // return record instanceof RecordPlaintext |
| 2500 | + // ? record |
| 2501 | + // : RecordPlaintext.fromString(<string>record); |
| 2502 | + if (record && record instanceof RecordPlaintext) { |
| 2503 | + record = record.toString(); |
| 2504 | + } |
| 2505 | + return <OwnedRecord>({ |
| 2506 | + recordPlaintext: record, |
| 2507 | + programName: 'credits.aleo', |
| 2508 | + recordName: 'credits', |
| 2509 | + }) |
2512 | 2510 | } catch (e) {
|
2513 | 2511 | try {
|
2514 | 2512 | const recordProvider = <RecordProvider>this.recordProvider;
|
2515 |
| - return <RecordPlaintext>( |
2516 |
| - await recordProvider.findCreditsRecord( |
2517 |
| - amount, |
2518 |
| - true, |
2519 |
| - nonces, |
2520 |
| - params, |
2521 |
| - ) |
| 2513 | + return await recordProvider.findCreditsRecord( |
| 2514 | + amount, |
| 2515 | + { ...params, unspent: true, nonces } |
2522 | 2516 | );
|
2523 | 2517 | } catch (e: any) {
|
2524 | 2518 | logAndThrow(
|
|
0 commit comments