Skip to content

Commit

Permalink
fix server getContractWasm and cleanup imports and fix accidental tim…
Browse files Browse the repository at this point in the history
…eout change
  • Loading branch information
BlaineHeffron committed May 8, 2024
1 parent c7583e7 commit 0ce5e48
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/contract_client/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Contract, ContractSpec, xdr } from "..";
import { ContractSpec, xdr } from "..";
import { Server } from '../soroban';
import { AssembledTransaction } from "./assembled_transaction";
import type { ContractClientOptions, MethodOptions } from "./types";
Expand Down
10 changes: 5 additions & 5 deletions src/contract_client/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-ignore
import * as jsxdr from "@stellar/js-xdr";
import { xdr } from "@stellar/stellar-base";
import { XdrReader } from "@stellar/js-xdr";
import { xdr } from "..";

/**
* The default timeout for waiting for a transaction to be included in a block.
*/
export const DEFAULT_TIMEOUT = 10;
export const DEFAULT_TIMEOUT = 5 * 60;

/**
* Keep calling a `fn` for `timeoutInSeconds` seconds, if `keepWaitingIf` is true.
Expand Down Expand Up @@ -89,8 +89,8 @@ export function implementsToString(obj: unknown): obj is { toString(): string }
* Reads a binary stream of ScSpecEntries into an array for processing by ContractSpec
*/
export function processSpecEntryStream(buffer: Buffer) {
let reader = new jsxdr.XdrReader(buffer);
let res: xdr.ScSpecEntry[] = [];
const reader = new XdrReader(buffer);
const res: xdr.ScSpecEntry[] = [];
while (reader._index < reader._length) {
res.push(xdr.ScSpecEntry.read(reader));
}
Expand Down
26 changes: 4 additions & 22 deletions src/soroban/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,8 @@ export class Server {
* deployed on the Soroban network. The WASM bytecode represents the executable
* code of the contract.
*
* @param {string|Address|Contract} contract the contract ID containing the
* WASM bytecode to retrieve, as a strkey (`C...` form), a {@link Contract},
* or an {@link Address} instance
* @param {string} contractId the contract ID containing the
* WASM bytecode to retrieve
*
* @returns {Promise<Buffer>} a Buffer containing the WASM bytecode
*
Expand All @@ -261,27 +260,10 @@ export class Server {
* });
*/
public async getContractWasm(
contract: string | Address | Contract
contractId: string
): Promise<Buffer> {
// coalesce `contract` param variants to an ScAddress
let scAddress: xdr.ScAddress;
if (typeof contract === 'string') {
scAddress = new Contract(contract).address().toScAddress();
} else if (contract instanceof Address) {
scAddress = contract.toScAddress();
} else if (contract instanceof Contract) {
scAddress = contract.address().toScAddress();
} else {
throw new TypeError(`unknown contract type: ${contract}`);
}

const contractLedgerKey = xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: scAddress,
key: xdr.ScVal.scvSymbol('footprint'),
durability: xdr.ContractDataDurability.persistent()
})
);
const contractLedgerKey = new Contract(contractId).getFootprint();

const response = await this.getLedgerEntries(contractLedgerKey);
if (!response.entries.length || !response.entries[0]?.val) {
Expand Down

0 comments on commit 0ce5e48

Please sign in to comment.