@xcapit/shelter-sdk
Version:
SDK for Shelter smart contracts on Stellar
39 lines (38 loc) • 1.36 kB
JavaScript
import { Shelter } from "../shelter/shelter";
import { Client, Keypair } from "shelter-sdk";
import { StrKey, Address } from "@stellar/stellar-sdk";
import { Transaction } from "../transaction/transaction";
export class Foundry {
_steward;
_rpc;
_wasm;
_client;
constructor(_steward, _rpc, _wasm, _client = Client) {
this._steward = _steward;
this._rpc = _rpc;
this._wasm = _wasm;
this._client = _client;
}
async newShelter() {
return new Shelter(this._steward, this._rpc, new this._client({
contractId: await this._address(await this._deploy()),
networkPassphrase: await this._rpc.network(),
rpcUrl: this._rpc.url(),
publicKey: this._steward.publicKey(),
}));
}
async _deploy() {
return await this._client.deploy({ steward: this._steward.publicKey() }, {
wasmHash: this._wasm,
networkPassphrase: await this._rpc.network(),
rpcUrl: this._rpc.url(),
publicKey: this._steward.publicKey(),
});
}
async _address(rawTx) {
return this._addressOf(await new Transaction(rawTx, this._steward, this._rpc).result());
}
async _addressOf(txData) {
return StrKey.encodeContract(Address.fromScAddress(txData.returnValue.address()).toBuffer());
}
}