UNPKG

@xcapit/shelter-sdk

Version:

SDK for Shelter smart contracts on Stellar

65 lines (64 loc) 2.18 kB
import { Client, Keypair } from "shelter-sdk"; import { Transaction } from "../transaction/transaction"; import { Gate } from "../gate/gate"; import { Aid } from "../aid/aid"; export class Shelter { _steward; _rpc; _client; constructor(_steward, _rpc, _client) { this._steward = _steward; this._rpc = _rpc; this._client = _client; } static async connected(aSteward, aRpc, aShelterId) { return new this(aSteward, aRpc, new Client({ contractId: aShelterId, networkPassphrase: await aRpc.network(), rpcUrl: aRpc.url(), publicKey: aSteward.publicKey(), })); } async stewardId() { return (await this._client.steward()).result; } async boundAid(recipient, token, amount, expiration) { await this._txOf(await this._client.bound_aid({ recipient, token, amount, expiration, }), 'Bound Aid Error').result(); } async unboundAid(recipient, token) { await this._txOf(await this._client.unbound_aid({ recipient, token, }), 'Unbound Aid Error').result(); } id() { return this._client.options.contractId; } async aidOf(recipient, token) { return (await this._client.aid_of({ recipient, token })).result.amount; } async updateReleaseKey(releaseKey) { await this._txOf(await this._client.update_release_key({ steward_key: releaseKey, }), 'Update Release Key Error').result(); } async updateSteward(newSteward) { await this._txOf(await this._client.update_steward({ new_steward: newSteward.publicKey(), }), 'Update Steward Error').result(); } gate() { return new Gate(this._client, this._steward, this._rpc); } async withdraw(sac, pass) { await new Aid(this._steward, this._steward, sac, this, this._rpc).transfer(this._steward.publicKey(), (await sac.balance({ id: this.id() })).result, pass); } _txOf(aRawTx, errorMsg) { return new Transaction(aRawTx, this._steward, this._rpc, errorMsg); } }