UNPKG

@dioxide-js/silas

Version:

RPC utility for Silas

62 lines (59 loc) 2.34 kB
import { __awaiter } from '../node_modules/tslib/tslib.es6.mjs'; import { isUndefined } from '../utils/index.mjs'; import Fetcher from './request.mjs'; import { isValidAddress } from '../utils/validator.mjs'; import { fullAddress } from '../utils/string.mjs'; import { toUint8Array } from '../utils/buffer.mjs'; import { DIOAddress } from '../utils/address/index.mjs'; class AddressService extends Fetcher { checkAddress(address) { if (!address || !isValidAddress(address)) { throw new Error('Address is not valid'); } } generate() { return __awaiter(this, arguments, void 0, function* (alg = 'sm2', privatekey) { const pk = privatekey ? toUint8Array(privatekey) : undefined; const dioAddress = new DIOAddress(alg, pk); const result = yield dioAddress.generate(); return result; }); } getISN(address) { return __awaiter(this, void 0, void 0, function* () { const fullAddr = fullAddress(address); this.checkAddress(fullAddr); const resp = yield this.postToBC('dx.isn', { address: fullAddr }); return (resp === null || resp === void 0 ? void 0 : resp.ISN) || 0; }); } getTxnListByAddress(params) { return this.post('chain.address_listtxn', params); } getAddressState(data) { return this.post('chain.address_state', data); } getAddressInfo(address) { if (typeof address !== 'string') { throw `getDetailInfo error: address should be string`; } const fullAddr = fullAddress(address); const addr = fullAddr.replace(/#/g, '%23'); return this.post('chain.address_profile', { address: addr }); } getBalance(address) { const fullAddr = fullAddress(address); this.checkAddress(fullAddr); const addr = fullAddr.replace(/#/g, '%23'); return this.post('chain.address_balance', { address: addr }); } getUserRegState(params) { const { id, address } = params; if (isUndefined(id) && isUndefined(address)) { throw `eigther 'id' or 'address' is required`; } return this.post('user.reg_state', { id, address }); } } export { AddressService as default }; //# sourceMappingURL=address.mjs.map