|
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(
|
@@ -577,14 +577,12 @@ class ProgramManager {
|
577 | 577 | // Get the fee record from the account if it is not provided in the parameters
|
578 | 578 | try {
|
579 | 579 | feeRecord = privateFee
|
580 |
| - ? <RecordPlaintext>( |
581 |
| - await this.getCreditsRecord( |
| 580 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
582 | 581 | priorityFee,
|
583 | 582 | [],
|
584 | 583 | feeRecord,
|
585 | 584 | recordSearchParams,
|
586 |
| - ) |
587 |
| - ) |
| 585 | + )).recordPlaintext?? '') |
588 | 586 | : undefined;
|
589 | 587 | } catch (e: any) {
|
590 | 588 | logAndThrow(
|
@@ -955,14 +953,12 @@ class ProgramManager {
|
955 | 953 | // Get the fee record from the account if it is not provided in the parameters.
|
956 | 954 | try {
|
957 | 955 | feeRecord = privateFee
|
958 |
| - ? <RecordPlaintext>( |
959 |
| - await this.getCreditsRecord( |
| 956 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
960 | 957 | priorityFee,
|
961 | 958 | [],
|
962 | 959 | feeRecord,
|
963 | 960 | recordSearchParams,
|
964 |
| - ) |
965 |
| - ) |
| 961 | + )).recordPlaintext?? '') |
966 | 962 | : undefined;
|
967 | 963 | } catch (e: any) {
|
968 | 964 | logAndThrow(
|
@@ -1293,14 +1289,12 @@ class ProgramManager {
|
1293 | 1289 | // Get the fee record from the account if it is not provided in the parameters
|
1294 | 1290 | try {
|
1295 | 1291 | feeRecord = privateFee
|
1296 |
| - ? <RecordPlaintext>( |
1297 |
| - await this.getCreditsRecord( |
| 1292 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
1298 | 1293 | priorityFee,
|
1299 | 1294 | [],
|
1300 | 1295 | feeRecord,
|
1301 | 1296 | recordSearchParams,
|
1302 |
| - ) |
1303 |
| - ) |
| 1297 | + )).recordPlaintext?? '') |
1304 | 1298 | : undefined;
|
1305 | 1299 | } catch (e: any) {
|
1306 | 1300 | logAndThrow(
|
@@ -1566,27 +1560,23 @@ class ProgramManager {
|
1566 | 1560 | const nonces: string[] = [];
|
1567 | 1561 | if (requiresAmountRecord(transferType)) {
|
1568 | 1562 | // If the transfer type is private and requires an amount record, get it from the record provider
|
1569 |
| - amountRecord = <RecordPlaintext>( |
1570 |
| - await this.getCreditsRecord( |
| 1563 | + amountRecord = RecordPlaintext.fromString((await this.getCreditsRecord( |
1571 | 1564 | priorityFee,
|
1572 | 1565 | [],
|
1573 | 1566 | amountRecord,
|
1574 | 1567 | recordSearchParams,
|
1575 |
| - ) |
1576 |
| - ); |
| 1568 | + )).recordPlaintext?? ''); |
1577 | 1569 | nonces.push(amountRecord.nonce());
|
1578 | 1570 | } else {
|
1579 | 1571 | amountRecord = undefined;
|
1580 | 1572 | }
|
1581 | 1573 | feeRecord = privateFee
|
1582 |
| - ? <RecordPlaintext>( |
1583 |
| - await this.getCreditsRecord( |
| 1574 | + ? RecordPlaintext.fromString((await this.getCreditsRecord( |
1584 | 1575 | priorityFee,
|
1585 | 1576 | nonces,
|
1586 | 1577 | feeRecord,
|
1587 | 1578 | recordSearchParams,
|
1588 |
| - ) |
1589 |
| - ) |
| 1579 | + )).recordPlaintext?? '') |
1590 | 1580 | : undefined;
|
1591 | 1581 | } catch (e: any) {
|
1592 | 1582 | logAndThrow(
|
@@ -2553,21 +2543,25 @@ class ProgramManager {
|
2553 | 2543 | nonces: string[],
|
2554 | 2544 | record?: RecordPlaintext | string,
|
2555 | 2545 | params?: RecordSearchParams,
|
2556 |
| - ): Promise<RecordPlaintext> { |
| 2546 | + ): Promise<OwnedRecord> { |
2557 | 2547 | try {
|
2558 |
| - return record instanceof RecordPlaintext |
2559 |
| - ? record |
2560 |
| - : RecordPlaintext.fromString(<string>record); |
| 2548 | + // return record instanceof RecordPlaintext |
| 2549 | + // ? record |
| 2550 | + // : RecordPlaintext.fromString(<string>record); |
| 2551 | + if (record && record instanceof RecordPlaintext) { |
| 2552 | + record = record.toString(); |
| 2553 | + } |
| 2554 | + return <OwnedRecord>({ |
| 2555 | + recordPlaintext: record, |
| 2556 | + programName: 'credits.aleo', |
| 2557 | + recordName: 'credits', |
| 2558 | + }) |
2561 | 2559 | } catch (e) {
|
2562 | 2560 | try {
|
2563 | 2561 | const recordProvider = <RecordProvider>this.recordProvider;
|
2564 |
| - return <RecordPlaintext>( |
2565 |
| - await recordProvider.findCreditsRecord( |
2566 |
| - amount, |
2567 |
| - true, |
2568 |
| - nonces, |
2569 |
| - params, |
2570 |
| - ) |
| 2562 | + return await recordProvider.findCreditsRecord( |
| 2563 | + amount, |
| 2564 | + { ...params, unspent: true, nonces } |
2571 | 2565 | );
|
2572 | 2566 | } catch (e: any) {
|
2573 | 2567 | logAndThrow(
|
|
0 commit comments