@xcapit/shelter-sdk
Version:
SDK for Shelter smart contracts on Stellar
31 lines (30 loc) • 1.07 kB
JavaScript
import { rpc } from "@stellar/stellar-sdk";
export class SimulatedTransaction {
_rawTx;
_signer;
_rpc;
constructor(_rawTx, _signer, _rpc) {
this._rawTx = _rawTx;
this._signer = _signer;
this._rpc = _rpc;
}
async result() {
console.log('simulate tx init');
const tx = this._rawTx.built;
console.log('built raw tx', tx);
const simTx = await this._rpc.server().simulateTransaction(tx);
console.log('simulated 1, result:', simTx);
// const assembledTx = this._rpc.assembleTransaction(tx, simTx);
// console.log('assembled tx:', assembledTx);
const completeTx = this._rpc.assembleTransaction(tx, simTx).build();
console.log('simulated 2, completeTx:', completeTx);
completeTx.sign(this._signer);
console.log('signed');
return await this._txData(completeTx);
}
async _txData(tx) {
return await this._rpc
.server()
.pollTransaction((await this._rpc.server().sendTransaction(tx)).hash);
}
}