|
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.
|
@@ -353,14 +355,12 @@ class ProgramManager {
|
353 | 355 | // Get the fee record from the account if it is not provided in the parameters
|
354 | 356 | try {
|
355 | 357 | feeRecord = privateFee
|
356 |
| - ? <RecordPlaintext>( |
357 |
| - await this.getCreditsRecord( |
| 358 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
358 | 359 | priorityFee,
|
359 | 360 | [],
|
360 | 361 | feeRecord,
|
361 | 362 | recordSearchParams,
|
362 |
| - ) |
363 |
| - ) |
| 363 | + )).recordPlaintext?? '') |
364 | 364 | : undefined;
|
365 | 365 | } catch (e: any) {
|
366 | 366 | logAndThrow(
|
@@ -583,14 +583,12 @@ class ProgramManager {
|
583 | 583 | // Get the fee record from the account if it is not provided in the parameters
|
584 | 584 | try {
|
585 | 585 | feeRecord = privateFee
|
586 |
| - ? <RecordPlaintext>( |
587 |
| - await this.getCreditsRecord( |
| 586 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
588 | 587 | priorityFee,
|
589 | 588 | [],
|
590 | 589 | feeRecord,
|
591 | 590 | recordSearchParams,
|
592 |
| - ) |
593 |
| - ) |
| 591 | + )).recordPlaintext?? '') |
594 | 592 | : undefined;
|
595 | 593 | } catch (e: any) {
|
596 | 594 | logAndThrow(
|
@@ -976,14 +974,12 @@ class ProgramManager {
|
976 | 974 | // Get the fee record from the account if it is not provided in the parameters.
|
977 | 975 | try {
|
978 | 976 | feeRecord = privateFee
|
979 |
| - ? <RecordPlaintext>( |
980 |
| - await this.getCreditsRecord( |
| 977 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
981 | 978 | priorityFee,
|
982 | 979 | [],
|
983 | 980 | feeRecord,
|
984 | 981 | recordSearchParams,
|
985 |
| - ) |
986 |
| - ) |
| 982 | + )).recordPlaintext?? '') |
987 | 983 | : undefined;
|
988 | 984 | } catch (e: any) {
|
989 | 985 | logAndThrow(
|
@@ -1314,14 +1310,12 @@ class ProgramManager {
|
1314 | 1310 | // Get the fee record from the account if it is not provided in the parameters
|
1315 | 1311 | try {
|
1316 | 1312 | feeRecord = privateFee
|
1317 |
| - ? <RecordPlaintext>( |
1318 |
| - await this.getCreditsRecord( |
| 1313 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
1319 | 1314 | priorityFee,
|
1320 | 1315 | [],
|
1321 | 1316 | feeRecord,
|
1322 | 1317 | recordSearchParams,
|
1323 |
| - ) |
1324 |
| - ) |
| 1318 | + )).recordPlaintext?? '') |
1325 | 1319 | : undefined;
|
1326 | 1320 | } catch (e: any) {
|
1327 | 1321 | logAndThrow(
|
@@ -1587,27 +1581,23 @@ class ProgramManager {
|
1587 | 1581 | const nonces: string[] = [];
|
1588 | 1582 | if (requiresAmountRecord(transferType)) {
|
1589 | 1583 | // If the transfer type is private and requires an amount record, get it from the record provider
|
1590 |
| - amountRecord = <RecordPlaintext>( |
1591 |
| - await this.getCreditsRecord( |
| 1584 | + amountRecord = RecordPlaintext.fromString((await this.getCreditsRecord( |
1592 | 1585 | priorityFee,
|
1593 | 1586 | [],
|
1594 | 1587 | amountRecord,
|
1595 | 1588 | recordSearchParams,
|
1596 |
| - ) |
1597 |
| - ); |
| 1589 | + )).recordPlaintext?? ''); |
1598 | 1590 | nonces.push(amountRecord.nonce());
|
1599 | 1591 | } else {
|
1600 | 1592 | amountRecord = undefined;
|
1601 | 1593 | }
|
1602 | 1594 | feeRecord = privateFee
|
1603 |
| - ? <RecordPlaintext>( |
1604 |
| - await this.getCreditsRecord( |
| 1595 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
1605 | 1596 | priorityFee,
|
1606 | 1597 | nonces,
|
1607 | 1598 | feeRecord,
|
1608 | 1599 | recordSearchParams,
|
1609 |
| - ) |
1610 |
| - ) |
| 1600 | + )).recordPlaintext?? '') |
1611 | 1601 | : undefined;
|
1612 | 1602 | } catch (e: any) {
|
1613 | 1603 | logAndThrow(
|
@@ -2574,21 +2564,25 @@ class ProgramManager {
|
2574 | 2564 | nonces: string[],
|
2575 | 2565 | record?: RecordPlaintext | string,
|
2576 | 2566 | params?: RecordSearchParams,
|
2577 |
| - ): Promise<RecordPlaintext> { |
| 2567 | + ): Promise<OwnedRecord> { |
2578 | 2568 | try {
|
2579 |
| - return record instanceof RecordPlaintext |
2580 |
| - ? record |
2581 |
| - : RecordPlaintext.fromString(<string>record); |
| 2569 | + // return record instanceof RecordPlaintext |
| 2570 | + // ? record |
| 2571 | + // : RecordPlaintext.fromString(<string>record); |
| 2572 | + if (record && record instanceof RecordPlaintext) { |
| 2573 | + record = record.toString(); |
| 2574 | + } |
| 2575 | + return <OwnedRecord>({ |
| 2576 | + recordPlaintext: record, |
| 2577 | + programName: 'credits.aleo', |
| 2578 | + recordName: 'credits', |
| 2579 | + }) |
2582 | 2580 | } catch (e) {
|
2583 | 2581 | try {
|
2584 | 2582 | const recordProvider = <RecordProvider>this.recordProvider;
|
2585 |
| - return <RecordPlaintext>( |
2586 |
| - await recordProvider.findCreditsRecord( |
2587 |
| - amount, |
2588 |
| - true, |
2589 |
| - nonces, |
2590 |
| - params, |
2591 |
| - ) |
| 2583 | + return await recordProvider.findCreditsRecord( |
| 2584 | + amount, |
| 2585 | + { ...params, unspent: true, nonces } |
2592 | 2586 | );
|
2593 | 2587 | } catch (e: any) {
|
2594 | 2588 | logAndThrow(
|
|
0 commit comments