diff --git a/README.md b/README.md index 5d7f32aa..a2c3c67c 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ import { DefaultProviderUrls, IAccount, IProvider, - ProviderType + ProviderType } from "@massalabs/massa-web3"; // create a base account for signing transactions @@ -50,7 +50,7 @@ import { DefaultProviderUrls, IAccount, IProvider, - ProviderType + ProviderType } from "@massalabs/massa-web3"; // create a base account for signing transactions @@ -307,9 +307,9 @@ Available class methods are: baseAccount ); ``` -- `getAccountSequentialBalance` +- `getAccountBalance` ```ts - const balance: IBalance = await web3Client.wallet().getAccountSequentialBalance("A12PWTzCKkkE9P5Supt3Fkb4QVZ3cdfB281TGaup7Nv1DY12a6F1"); + const balance: IBalance = await web3Client.wallet().getAccountBalance("A12PWTzCKkkE9P5Supt3Fkb4QVZ3cdfB281TGaup7Nv1DY12a6F1"); ``` In addition to the class methods, there are also static methods for direct use: @@ -455,10 +455,10 @@ const status: EOperationStatus = await web3Client.smartContracts().awaitRequired ### Smart contract balance -Smart contract balances could be easily obtained via usign the `getParallelBalance` method: +Smart contract balances could be easily obtained via using the `getContractBalance` method: ```ts -const balance: IBalance|null = await web3Client.smartContracts().getParallelBalance(contractAddress); +const balance: IBalance|null = await web3Client.smartContracts().getContractBalance(contractAddress); ``` ### Smart contract read and write calls @@ -487,8 +487,7 @@ const data: Array = await web3Client.smartContracts().callSmartContract( fee: 0, gasPrice: 0, maxGas: 200000, - parallelCoins: 0, - sequentialCoins: 0, + coins: 0, targetAddress: scAddress, functionName: "play", parameter: JSON.stringify({index : 1}), @@ -509,4 +508,4 @@ const data: Array = await web3Client.smartContracts(). } as IContractData, baseAccount ); -``` \ No newline at end of file +``` diff --git a/examples/smartContracts/index.ts b/examples/smartContracts/index.ts index 55f39166..bd9f35b0 100644 --- a/examples/smartContracts/index.ts +++ b/examples/smartContracts/index.ts @@ -64,8 +64,7 @@ const ora = require("ora"); fee: 0, gasPrice: 0, maxGas: 200000, - parallelCoins: 0, - sequentialCoins: 0, + coins: 0, targetAddress: scAddress, functionName: "play", parameter: JSON.stringify({index : 1}), @@ -95,4 +94,4 @@ const ora = require("ora"); const msg = chalk.red(`Error = ${ex.message}`); if (spinner) spinner.fail(msg); } -})(); \ No newline at end of file +})(); diff --git a/src/interfaces/IAddressInfo.ts b/src/interfaces/IAddressInfo.ts index 42a32fcf..fb1b869c 100644 --- a/src/interfaces/IAddressInfo.ts +++ b/src/interfaces/IAddressInfo.ts @@ -17,43 +17,41 @@ export interface ILedgerDatastore { [name: string]: [number]; } +export interface ICycleInfos { + active_rolls: number; + cycle: number; + is_final: boolean; + nok_count: number; + ok_count: number; +} + +export interface IDeferredCredits { + slot: { + period: number, + thread: number, + }; + amount: number; +} + export interface IAddressInfo { address: string; - balance: { - candidate_balance: string, // represent an Amount in coins - final_balance: string, // represent an Amount in coins - locked_balance: string, // represent an Amount in coins - }; - block_draws: [ + candidate_balance: string; // represent an Amount in coins + candidate_datastore_keys: string; + candidate_roll_count: number; + created_blocks: Array; + created_endorsements: Array; + created_operations: Array; + cycle_infos: Array; + deferred_credits: Array; + final_balance: string; // represent an Amount in coins + final_datastore_keys: Array; + final_roll_count: number; + next_block_draws: [ { period: number, thread: number, }, ]; - blocks_created: [string]; // Block ids - endorsement_draws: Array; - involved_in_endorsements: [string]; // Endorsement Id - involved_in_operations: [string]; // Operation id - production_stats: Array; - rolls: { - active_rolls: number, - candidate_rolls: number, - final_rolls: number, - }; + next_endorsement_draws: Array; thread: number; - ledger_info: { - candidate_ledger_info: {balance: string} // represents an amount - final_ledger_info: {balance: string} // stored bytecode - locked_balance: string - }; - final_sce_ledger_info: { - balance: string // represents an amount - module: null | [number] // stored bytecode - datastore: ILedgerDatastore - }; - candidate_sce_ledger_info: { - balance: string // represents an amount - module: null | [number] // stored bytecode - datastore: ILedgerDatastore - }; } \ No newline at end of file diff --git a/src/interfaces/ICallData.ts b/src/interfaces/ICallData.ts index e7d66082..ea89ccd8 100644 --- a/src/interfaces/ICallData.ts +++ b/src/interfaces/ICallData.ts @@ -5,10 +5,8 @@ export interface ICallData { maxGas: number; /// The price per unit of gas that the caller is willing to pay for the execution. gasPrice: number; - /// Extra coins that are spent from the caller's parallel balance and transferred to the target - parallelCoins: number; - /// Extra coins that are spent from the caller's sequential balance and transferred to the target - sequentialCoins: number; + /// Extra coins that are spent from the caller's balance and transferred to the target + coins: number; /// Target smart contract address targetAddress: string; /// Target function name. No function is called if empty. diff --git a/src/interfaces/ISmartContractsClient.ts b/src/interfaces/ISmartContractsClient.ts index e723b738..ff0a6a3c 100644 --- a/src/interfaces/ISmartContractsClient.ts +++ b/src/interfaces/ISmartContractsClient.ts @@ -14,7 +14,7 @@ export interface ISmartContractsClient { deploySmartContract(contractData: IContractData, executor?: IAccount): Promise>; callSmartContract(callData: ICallData, executor?: IAccount): Promise>; readSmartContract(readData: IReadData): Promise>; - getParallelBalance(address: string): Promise; + getContractBalance(address: string): Promise; getFilteredScOutputEvents(eventFilterData: IEventFilter): Promise>; executeReadOnlySmartContract(contractData: IContractData): Promise>; getOperationStatus(opId: string): Promise; diff --git a/src/interfaces/IWalletClient.ts b/src/interfaces/IWalletClient.ts index 0525fedf..8abc26f8 100644 --- a/src/interfaces/IWalletClient.ts +++ b/src/interfaces/IWalletClient.ts @@ -16,7 +16,7 @@ export interface IWalletClient { removeAddressesFromWallet(addresses: Array): void; walletInfo(): Promise>; signMessage(data: string | Buffer, accountSignerAddress: string): Promise; - getAccountSequentialBalance(address: string): Promise; + getAccountBalance(address: string): Promise; sendTransaction(txData: ITransactionData, executor: IAccount): Promise>; buyRolls(txData: IRollsData, executor: IAccount): Promise>; sellRolls(txData: IRollsData, executor: IAccount): Promise>; diff --git a/src/interfaces/OperationTypes.ts b/src/interfaces/OperationTypes.ts index 88243960..c9219b0e 100644 --- a/src/interfaces/OperationTypes.ts +++ b/src/interfaces/OperationTypes.ts @@ -30,9 +30,8 @@ export interface ICallSmartContractOpType { CallSC: { gas_price: string; max_gas: number; - parallel_coins: string; param: string; - sequential_coins: string; + coins: string; target_addr: string; target_func: string; }; diff --git a/src/web3/BaseClient.ts b/src/web3/BaseClient.ts index bfa1ab8d..3f959bb2 100755 --- a/src/web3/BaseClient.ts +++ b/src/web3/BaseClient.ts @@ -183,11 +183,8 @@ export class BaseClient { // max gas const maxGasEncoded = Buffer.from(varintEncode((data as ICallData).maxGas)); - // parallel coins to send - const parallelCoinsEncoded = Buffer.from(varintEncode((data as ICallData).parallelCoins)); - - // sequential coins to send - const sequentialCoinsEncoded = Buffer.from(varintEncode((data as ICallData).sequentialCoins)); + // coins to send + const coinsEncoded = Buffer.from(varintEncode((data as ICallData).coins)); // gas price const gasPriceEncoded = Buffer.from(varintEncode((data as ICallData).gasPrice)); @@ -203,7 +200,8 @@ export class BaseClient { const parametersEncoded = new Uint8Array(Buffer.from((data as ICallData).parameter, "utf8")); const parametersLengthEncoded = Buffer.from(varintEncode(parametersEncoded.length)); - return Buffer.concat([feeEncoded, expirePeriodEncoded, typeIdEncoded, maxGasEncoded, parallelCoinsEncoded, sequentialCoinsEncoded, gasPriceEncoded, targetAddressEncoded, functionNameLengthEncoded, functionNameEncoded, parametersLengthEncoded, parametersEncoded]); + return Buffer.concat([feeEncoded, expirePeriodEncoded, typeIdEncoded, maxGasEncoded, coinsEncoded, gasPriceEncoded, targetAddressEncoded, + functionNameLengthEncoded, functionNameEncoded, parametersLengthEncoded, parametersEncoded]); } case OperationTypeId.Transaction: { // transfer amount diff --git a/src/web3/Client.ts b/src/web3/Client.ts index db2bcbcf..9b5b7e76 100755 --- a/src/web3/Client.ts +++ b/src/web3/Client.ts @@ -17,7 +17,7 @@ export class Client implements IClient { private smartContractsClient: SmartContractsClient; private vaultClient: VaultClient; - public constructor(clientConfig: IClientConfig, baseAccount?: IAccount) { + public constructor(private clientConfig: IClientConfig, baseAccount?: IAccount) { this.publicApiClient = new PublicApiClient(clientConfig); this.privateApiClient = new PrivateApiClient(clientConfig); this.walletClient = new WalletClient(clientConfig, this.publicApiClient, baseAccount); @@ -66,6 +66,12 @@ export class Client implements IClient { this.smartContractsClient.setProviders(providers); } + /** get currently set providers */ + public getProviders(): Array { + return this.clientConfig.providers; + } + + /** sets a new default provider */ public setNewDefaultProvider(provider: DefaultProviderUrls): void { const providers = new Array({ url: provider, diff --git a/src/web3/SmartContractsClient.ts b/src/web3/SmartContractsClient.ts index b9d53c23..c0efe0ad 100644 --- a/src/web3/SmartContractsClient.ts +++ b/src/web3/SmartContractsClient.ts @@ -20,7 +20,6 @@ import { JSON_RPC_REQUEST_METHOD } from "../interfaces/JsonRpcMethods"; import { OperationTypeId } from "../interfaces/OperationTypes"; import { trySafeExecute } from "../utils/retryExecuteFunction"; import { wait } from "../utils/Wait"; -import { base58Encode, hashBlake3 } from "../utils/Xbqcrypto"; import { BaseClient } from "./BaseClient"; import { PublicApiClient } from "./PublicApiClient"; import { WalletClient } from "./WalletClient"; @@ -42,7 +41,7 @@ export class SmartContractsClient extends BaseClient implements ISmartContractsC this.getOperationStatus = this.getOperationStatus.bind(this); this.callSmartContract = this.callSmartContract.bind(this); this.readSmartContract = this.readSmartContract.bind(this); - this.getParallelBalance = this.getParallelBalance.bind(this); + this.getContractBalance = this.getContractBalance.bind(this); } /** create and send an operation containing byte code */ @@ -135,14 +134,14 @@ export class SmartContractsClient extends BaseClient implements ISmartContractsC } } - /** Returns the parallel balance which is the smart contract side balance */ - public async getParallelBalance(address: string): Promise { + /** Returns the balance of the smart contract */ + public async getContractBalance(address: string): Promise { const addresses: Array = await this.publicApiClient.getAddresses([address]); if (addresses.length === 0) return null; const addressInfo: IAddressInfo = addresses.at(0); return { - candidate: addressInfo.candidate_sce_ledger_info.balance, - final: addressInfo.final_sce_ledger_info.balance + candidate: addressInfo.candidate_balance, + final: addressInfo.final_balance } as IBalance; } diff --git a/src/web3/WalletClient.ts b/src/web3/WalletClient.ts index 098d3abc..0b135b45 100755 --- a/src/web3/WalletClient.ts +++ b/src/web3/WalletClient.ts @@ -54,7 +54,7 @@ export class WalletClient extends BaseClient implements IWalletClient { this.sendTransaction = this.sendTransaction.bind(this); this.sellRolls = this.sellRolls.bind(this); this.buyRolls = this.buyRolls.bind(this); - this.getAccountSequentialBalance = this.getAccountSequentialBalance.bind(this); + this.getAccountBalance = this.getAccountBalance.bind(this); } /** set the default (base) account */ @@ -326,14 +326,14 @@ export class WalletClient extends BaseClient implements IWalletClient { return secretKeyBase58Decoded; } - /** Returns the account sequential balance - the consensus side balance */ - public async getAccountSequentialBalance(address: string): Promise { + /** Returns the account balance */ + public async getAccountBalance(address: string): Promise { const addresses: Array = await this.publicApiClient.getAddresses([address]); if (addresses.length === 0) return null; const addressInfo: IAddressInfo = addresses.at(0); return { - candidate: addressInfo.ledger_info.candidate_ledger_info.balance, - final: addressInfo.ledger_info.final_ledger_info.balance + candidate: addressInfo.candidate_balance, + final: addressInfo.final_balance } as IBalance; }