UNPKG

@celo/contractkit

Version:

Celo's ContractKit to interact with Celo network

79 lines 3.6 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContractKit = exports.MiniContractKit = exports.newKitFromWeb3 = exports.newKitWithApiKey = exports.newKit = void 0; const connect_1 = require("@celo/connect"); const wallet_local_1 = require("@celo/wallet-local"); const address_registry_1 = require("./address-registry"); const celo_tokens_1 = require("./celo-tokens"); const mini_contract_cache_1 = require("./mini-contract-cache"); const setupForKits_1 = require("./setupForKits"); /** * Creates a new instance of `MiniMiniContractKit` given a nodeUrl * @param url CeloBlockchain node url * @param wallet to reuse or add a wallet different than the default (example ledger-wallet) * @param options to pass to the Web3 HttpProvider constructor */ function newKit(url, wallet, options) { const web3 = (0, setupForKits_1.getWeb3ForKit)(url, options); return newKitFromWeb3(web3, wallet); } exports.newKit = newKit; /** * Creates a new instance of `MiniContractKit` given a nodeUrl and apiKey * @param url CeloBlockchain node url * @param apiKey to include in the http request header * @param wallet to reuse or add a wallet different than the default (example ledger-wallet) */ function newKitWithApiKey(url, apiKey, wallet) { const options = (0, setupForKits_1.setupAPIKey)(apiKey); return newKit(url, wallet, options); } exports.newKitWithApiKey = newKitWithApiKey; /** * Creates a new instance of the `MiniContractKit` with a web3 instance * @param web3 Web3 instance */ function newKitFromWeb3(web3, wallet = new wallet_local_1.LocalWallet()) { (0, setupForKits_1.ensureCurrentProvider)(web3); return new MiniContractKit(new connect_1.Connection(web3, wallet)); } exports.newKitFromWeb3 = newKitFromWeb3; /** * MiniContractKit provides a core subset of {@link ContractKit}'s functionality * * @remarks * * It is recommended to use this over ContractKit for dApps as it is lighter * * @param connection – an instance of @celo/connect {@link Connection} */ class MiniContractKit { constructor(connection) { this.connection = connection; this.registry = new address_registry_1.AddressRegistry(connection); this.contracts = new mini_contract_cache_1.MiniContractCache(connection, this.registry); this.celoTokens = new celo_tokens_1.CeloTokens(this.contracts, this.registry); } getWallet() { return this.connection.wallet; } // Like get Total Balance on MiniContractKit but does not include locked celo or pending getTotalBalance(address) { return __awaiter(this, void 0, void 0, function* () { return Object.assign({}, (yield this.celoTokens.balancesOf(address))); }); } } exports.MiniContractKit = MiniContractKit; // For easy switching from full contractKit to Mini exports.ContractKit = MiniContractKit; //# sourceMappingURL=mini-kit.js.map