diff --git a/src/contract_spec.ts b/src/contract_spec.ts index 91add10fb..dc80f9a1d 100644 --- a/src/contract_spec.ts +++ b/src/contract_spec.ts @@ -1,4 +1,4 @@ -import { JSONSchema7, JSONSchema7Definition } from "json-schema"; +import type { JSONSchema7, JSONSchema7Definition } from "json-schema"; import { ScIntType, XdrLargeInt, @@ -6,8 +6,8 @@ import { Address, Contract, scValToBigInt, -} from "."; -import { Ok } from "./rust_types"; +} from "@stellar/stellar-base" +import { Ok } from "./soroban/contract_client/rust_result" export interface Union { tag: string; @@ -65,7 +65,7 @@ export class ContractSpec { let entry = entries[0]; if (typeof entry === "string") { this.entries = (entries as string[]).map((s) => - xdr.ScSpecEntry.fromXDR(s, "base64") + xdr.ScSpecEntry.fromXDR(s, "base64"), ); } else { this.entries = entries as xdr.ScSpecEntry[]; @@ -83,7 +83,7 @@ export class ContractSpec { .filter( (entry) => entry.switch().value === - xdr.ScSpecEntryKind.scSpecEntryFunctionV0().value + xdr.ScSpecEntryKind.scSpecEntryFunctionV0().value, ) .map((entry) => entry.functionV0()); } @@ -164,9 +164,7 @@ export class ContractSpec { } let output = outputs[0]; if (output.switch().value === xdr.ScSpecType.scSpecTypeResult().value) { - return new Ok( - this.scValToNative(val, output.result().okType()) - ); + return new Ok(this.scValToNative(val, output.result().okType())); } return this.scValToNative(val, output); } @@ -181,7 +179,7 @@ export class ContractSpec { */ findEntry(name: string): xdr.ScSpecEntry { let entry = this.entries.find( - (entry) => entry.value().name().toString() === name + (entry) => entry.value().name().toString() === name, ); if (!entry) { throw new Error(`no such entry: ${name}`); @@ -220,7 +218,7 @@ export class ContractSpec { return xdr.ScVal.scvVoid(); default: throw new TypeError( - `Type ${ty} was not void, but value was null` + `Type ${ty} was not void, but value was null`, ); } } @@ -232,7 +230,7 @@ export class ContractSpec { if (val instanceof Address) { if (ty.switch().value !== xdr.ScSpecType.scSpecTypeAddress().value) { throw new TypeError( - `Type ${ty} was not address, but value was Address` + `Type ${ty} was not address, but value was Address`, ); } return val.toScVal(); @@ -241,7 +239,7 @@ export class ContractSpec { if (val instanceof Contract) { if (ty.switch().value !== xdr.ScSpecType.scSpecTypeAddress().value) { throw new TypeError( - `Type ${ty} was not address, but value was Address` + `Type ${ty} was not address, but value was Address`, ); } return val.address().toScVal(); @@ -254,7 +252,7 @@ export class ContractSpec { let bytes_n = ty.bytesN(); if (copy.length !== bytes_n.n()) { throw new TypeError( - `expected ${bytes_n.n()} bytes, but got ${copy.length}` + `expected ${bytes_n.n()} bytes, but got ${copy.length}`, ); } //@ts-ignore @@ -265,7 +263,7 @@ export class ContractSpec { return xdr.ScVal.scvBytes(copy); default: throw new TypeError( - `invalid type (${ty}) specified for Bytes and BytesN` + `invalid type (${ty}) specified for Bytes and BytesN`, ); } } @@ -275,7 +273,7 @@ export class ContractSpec { let vec = ty.vec(); let elementType = vec.elementType(); return xdr.ScVal.scvVec( - val.map((v) => this.nativeToScVal(v, elementType)) + val.map((v) => this.nativeToScVal(v, elementType)), ); } case xdr.ScSpecType.scSpecTypeTuple().value: { @@ -283,11 +281,11 @@ export class ContractSpec { let valTypes = tup.valueTypes(); if (val.length !== valTypes.length) { throw new TypeError( - `Tuple expects ${valTypes.length} values, but ${val.length} were provided` + `Tuple expects ${valTypes.length} values, but ${val.length} were provided`, ); } return xdr.ScVal.scvVec( - val.map((v, i) => this.nativeToScVal(v, valTypes[i])) + val.map((v, i) => this.nativeToScVal(v, valTypes[i])), ); } case xdr.ScSpecType.scSpecTypeMap().value: { @@ -299,13 +297,13 @@ export class ContractSpec { let key = this.nativeToScVal(entry[0], keyType); let val = this.nativeToScVal(entry[1], valueType); return new xdr.ScMapEntry({ key, val }); - }) + }), ); } default: throw new TypeError( - `Type ${ty} was not vec, but value was Array` + `Type ${ty} was not vec, but value was Array`, ); } } @@ -330,14 +328,13 @@ export class ContractSpec { if ((val.constructor?.name ?? "") !== "Object") { throw new TypeError( - `cannot interpret ${ - val.constructor?.name - } value as ScVal (${JSON.stringify(val)})` + `cannot interpret ${val.constructor?.name + } value as ScVal (${JSON.stringify(val)})`, ); } throw new TypeError( - `Received object ${val} did not match the provided type ${ty}` + `Received object ${val} did not match the provided type ${ty}`, ); } @@ -380,7 +377,7 @@ export class ContractSpec { return xdr.ScVal.scvVoid(); default: throw new TypeError( - `Type ${ty} was not void, but value was undefined` + `Type ${ty} was not void, but value was undefined`, ); } } @@ -399,7 +396,7 @@ export class ContractSpec { case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0(): if (typeof val !== "number") { throw new TypeError( - `expected number for enum ${name}, but got ${typeof val}` + `expected number for enum ${name}, but got ${typeof val}`, ); } return this.nativeToEnum(val as number, entry.udtEnumV0()); @@ -414,7 +411,7 @@ export class ContractSpec { private nativeToUnion( val: Union, - union_: xdr.ScSpecUdtUnionV0 + union_: xdr.ScSpecUdtUnionV0, ): xdr.ScVal { let entry_name = val.tag; let case_ = union_.cases().find((entry) => { @@ -434,11 +431,11 @@ export class ContractSpec { if (Array.isArray(val.values)) { if (val.values.length != types.length) { throw new TypeError( - `union ${union_} expects ${types.length} values, but got ${val.values.length}` + `union ${union_} expects ${types.length} values, but got ${val.values.length}`, ); } let scvals = val.values.map((v, i) => - this.nativeToScVal(v, types[i]) + this.nativeToScVal(v, types[i]), ); scvals.unshift(key); return xdr.ScVal.scvVec(scvals); @@ -455,11 +452,11 @@ export class ContractSpec { if (fields.some(isNumeric)) { if (!fields.every(isNumeric)) { throw new Error( - "mixed numeric and non-numeric field names are not allowed" + "mixed numeric and non-numeric field names are not allowed", ); } return xdr.ScVal.scvVec( - fields.map((_, i) => this.nativeToScVal(val[i], fields[i].type())) + fields.map((_, i) => this.nativeToScVal(val[i], fields[i].type())), ); } return xdr.ScVal.scvMap( @@ -469,7 +466,7 @@ export class ContractSpec { key: this.nativeToScVal(name, xdr.ScSpecTypeDef.scSpecTypeSymbol()), val: this.nativeToScVal(val[name], field.type()), }); - }) + }), ); } @@ -531,13 +528,13 @@ export class ContractSpec { if (value == xdr.ScSpecType.scSpecTypeVec().value) { let vec = typeDef.vec(); return (scv.vec() ?? []).map((elm) => - this.scValToNative(elm, vec.elementType()) + this.scValToNative(elm, vec.elementType()), ) as T; } else if (value == xdr.ScSpecType.scSpecTypeTuple().value) { let tuple = typeDef.tuple(); let valTypes = tuple.valueTypes(); return (scv.vec() ?? []).map((elm, i) => - this.scValToNative(elm, valTypes[i]) + this.scValToNative(elm, valTypes[i]), ) as T; } throw new TypeError(`Type ${typeDef} was not vec, but ${scv} is`); @@ -562,8 +559,8 @@ export class ContractSpec { `ScSpecType ${t.name} was not map, but ${JSON.stringify( scv, null, - 2 - )} is` + 2, + )} is`, ); } @@ -581,9 +578,8 @@ export class ContractSpec { value !== xdr.ScSpecType.scSpecTypeSymbol().value ) { throw new Error( - `ScSpecType ${ - t.name - } was not string or symbol, but ${JSON.stringify(scv, null, 2)} is` + `ScSpecType ${t.name + } was not string or symbol, but ${JSON.stringify(scv, null, 2)} is`, ); } return scv.value()?.toString() as T; @@ -600,8 +596,8 @@ export class ContractSpec { `failed to convert ${JSON.stringify( scv, null, - 2 - )} to native type from type ${t.name}` + 2, + )} to native type from type ${t.name}`, ); } } @@ -617,7 +613,7 @@ export class ContractSpec { return this.unionToNative(scv, entry.udtUnionV0()); default: throw new Error( - `failed to parse udt ${udt.name().toString()}: ${entry}` + `failed to parse udt ${udt.name().toString()}: ${entry}`, ); } } @@ -629,7 +625,7 @@ export class ContractSpec { } if (vec.length === 0 && udt.cases.length !== 0) { throw new Error( - `${val} has length 0, but the there are at least one case in the union` + `${val} has length 0, but the there are at least one case in the union`, ); } let name = vec[0].sym().toString(); @@ -639,7 +635,7 @@ export class ContractSpec { let entry = udt.cases().find(findCase(name)); if (!entry) { throw new Error( - `failed to find entry ${name} in union {udt.name().toString()}` + `failed to find entry ${name} in union {udt.name().toString()}`, ); } let res: Union = { tag: name }; @@ -667,7 +663,7 @@ export class ContractSpec { let field = fields[i]; res[field.name().toString()] = this.scValToNative( entry.val(), - field.type() + field.type(), ); }); return res; @@ -692,7 +688,7 @@ export class ContractSpec { .filter( (entry) => entry.switch().value === - xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0().value + xdr.ScSpecEntryKind.scSpecEntryUdtErrorEnumV0().value, ) .flatMap((entry) => (entry.value() as xdr.ScSpecUdtErrorEnumV0).cases()); } @@ -1012,7 +1008,7 @@ function structToJsonSchema(udt: xdr.ScSpecUdtStructV0): object { if (fields.some(isNumeric)) { if (!fields.every(isNumeric)) { throw new Error( - "mixed numeric and non-numeric field names are not allowed" + "mixed numeric and non-numeric field names are not allowed", ); } let items = fields.map((_, i) => typeRef(fields[i].type())); @@ -1035,7 +1031,7 @@ function structToJsonSchema(udt: xdr.ScSpecUdtStructV0): object { } function args_and_required( - input: { type: () => xdr.ScSpecTypeDef; name: () => string | Buffer }[] + input: { type: () => xdr.ScSpecTypeDef; name: () => string | Buffer }[], ): { properties: object; required?: string[] } { let properties: any = {}; let required: string[] = []; @@ -1116,7 +1112,7 @@ function unionToJsonSchema(udt: xdr.ScSpecUdtUnionV0): any { tag: title, values: { type: "array", - items: c.type().map(typeRef) + items: c.type().map(typeRef), }, }, required: ["tag", "values"], @@ -1156,4 +1152,3 @@ function enumToJsonSchema(udt: xdr.ScSpecUdtEnumV0): any { } return res; } - diff --git a/src/rust_types/index.ts b/src/rust_types/index.ts deleted file mode 100644 index bb162e4c8..000000000 --- a/src/rust_types/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./result"; diff --git a/src/contract_client/assembled_transaction.ts b/src/soroban/contract_client/assembled_transaction.ts similarity index 94% rename from src/contract_client/assembled_transaction.ts rename to src/soroban/contract_client/assembled_transaction.ts index fad736533..a8436fc3d 100644 --- a/src/contract_client/assembled_transaction.ts +++ b/src/soroban/contract_client/assembled_transaction.ts @@ -1,25 +1,27 @@ /* disable max-classes rule, because extending error shouldn't count! */ /* eslint max-classes-per-file: 0 */ -import type { - AssembledTransactionOptions, - ContractClientOptions, - MethodOptions, - Tx, - XDR_BASE64, -} from "./types"; -import type { ContractClient } from "./client"; import { Account, BASE_FEE, Contract, Operation, - SorobanRpc, StrKey, TransactionBuilder, authorizeEntry, xdr, -} from ".."; -import { Err } from "../rust_types"; +} from "@stellar/stellar-base"; +import type { + AssembledTransactionOptions, + ContractClientOptions, + MethodOptions, + Tx, + XDR_BASE64, +} from "./types"; +import { Server } from "../server"; +import { Api } from "../api"; +import { assembleTransaction } from "../transaction"; +import type { ContractClient } from "./client"; +import { Err } from "./rust_result"; import { DEFAULT_TIMEOUT, contractErrorPattern, @@ -264,7 +266,7 @@ export class AssembledTransaction { * cached, serializable access to the data needed by AssembledTransaction * logic. */ - public simulation?: SorobanRpc.Api.SimulateTransactionResponse; + public simulation?: Api.SimulateTransactionResponse; /** * Cached simulation result. This is set after the first call to @@ -277,7 +279,7 @@ export class AssembledTransaction { * If you need access to this data after a transaction has been serialized * and then deserialized, you can call `simulationData.result`. */ - private simulationResult?: SorobanRpc.Api.SimulateHostFunctionResult; + private simulationResult?: Api.SimulateHostFunctionResult; /** * Cached simulation transaction data. This is set after the first call to @@ -296,7 +298,7 @@ export class AssembledTransaction { * The Soroban server to use for all RPC calls. This is constructed from the * `rpcUrl` in the options. */ - private server: SorobanRpc.Server; + private server: Server; /** * A list of the most important errors that various AssembledTransaction @@ -304,13 +306,13 @@ export class AssembledTransaction { * logic. */ static Errors = { - ExpiredState: class ExpiredStateError extends Error {}, - NeedsMoreSignatures: class NeedsMoreSignaturesError extends Error {}, - NoSignatureNeeded: class NoSignatureNeededError extends Error {}, - NoUnsignedNonInvokerAuthEntries: class NoUnsignedNonInvokerAuthEntriesError extends Error {}, - NoSigner: class NoSignerError extends Error {}, - NotYetSimulated: class NotYetSimulatedError extends Error {}, - FakeAccount: class FakeAccountError extends Error {}, + ExpiredState: class ExpiredStateError extends Error { }, + NeedsMoreSignatures: class NeedsMoreSignaturesError extends Error { }, + NoSignatureNeeded: class NoSignatureNeededError extends Error { }, + NoUnsignedNonInvokerAuthEntries: class NoUnsignedNonInvokerAuthEntriesError extends Error { }, + NoSigner: class NoSignerError extends Error { }, + NotYetSimulated: class NotYetSimulatedError extends Error { }, + FakeAccount: class FakeAccountError extends Error { }, }; /** @@ -364,7 +366,7 @@ export class AssembledTransaction { private constructor(public options: AssembledTransactionOptions) { this.options.simulate = this.options.simulate ?? true; - this.server = new SorobanRpc.Server(this.options.rpcUrl, { + this.server = new Server(this.options.rpcUrl, { allowHttp: this.options.allowHttp ?? false, }); } @@ -413,15 +415,15 @@ export class AssembledTransaction { if (!this.raw) { throw new Error( "Transaction has not yet been assembled; " + - "call `AssembledTransaction.build` first.", + "call `AssembledTransaction.build` first.", ); } this.built = this.raw.build(); this.simulation = await this.server.simulateTransaction(this.built); - if (SorobanRpc.Api.isSimulationSuccess(this.simulation)) { - this.built = SorobanRpc.assembleTransaction( + if (Api.isSimulationSuccess(this.simulation)) { + this.built = assembleTransaction( this.built, this.simulation, ).build(); @@ -431,7 +433,7 @@ export class AssembledTransaction { }; get simulationData(): { - result: SorobanRpc.Api.SimulateHostFunctionResult; + result: Api.SimulateHostFunctionResult; transactionData: xdr.SorobanTransactionData; } { if (this.simulationResult && this.simulationTransactionData) { @@ -446,11 +448,11 @@ export class AssembledTransaction { "Transaction has not yet been simulated", ); } - if (SorobanRpc.Api.isSimulationError(simulation)) { + if (Api.isSimulationError(simulation)) { throw new Error(`Transaction simulation failed: "${simulation.error}"`); } - if (SorobanRpc.Api.isSimulationRestore(simulation)) { + if (Api.isSimulationRestore(simulation)) { throw new AssembledTransaction.Errors.ExpiredState( `You need to restore some contract state before you can invoke this method. ${JSON.stringify( simulation, @@ -528,21 +530,21 @@ export class AssembledTransaction { if (!force && this.isReadCall) { throw new AssembledTransaction.Errors.NoSignatureNeeded( "This is a read call. It requires no signature or sending. " + - "Use `force: true` to sign and send anyway.", + "Use `force: true` to sign and send anyway.", ); } if (!signTransaction) { throw new AssembledTransaction.Errors.NoSigner( "You must provide a signTransaction function, either when calling " + - "`signAndSend` or when initializing your ContractClient", + "`signAndSend` or when initializing your ContractClient", ); } if (this.needsNonInvokerSigningBy().length) { throw new AssembledTransaction.Errors.NeedsMoreSignatures( "Transaction requires more signatures. " + - "See `needsNonInvokerSigningBy` for details.", + "See `needsNonInvokerSigningBy` for details.", ); } @@ -615,10 +617,10 @@ export class AssembledTransaction { .filter( (entry) => entry.credentials().switch() === - xdr.SorobanCredentialsType.sorobanCredentialsAddress() && + xdr.SorobanCredentialsType.sorobanCredentialsAddress() && (includeAlreadySigned || entry.credentials().address().signature().switch().name === - "scvVoid"), + "scvVoid"), ) .map((entry) => StrKey.encodeEd25519PublicKey( @@ -686,7 +688,7 @@ export class AssembledTransaction { if (!signAuthEntry) { throw new AssembledTransaction.Errors.NoSigner( "You must provide `signAuthEntry` when calling `signAuthEntries`, " + - "or when constructing the `ContractClient` or `AssembledTransaction`", + "or when constructing the `ContractClient` or `AssembledTransaction`", ); } diff --git a/src/contract_client/basic_node_signer.ts b/src/soroban/contract_client/basic_node_signer.ts similarity index 93% rename from src/contract_client/basic_node_signer.ts rename to src/soroban/contract_client/basic_node_signer.ts index 9bfe72192..db1834815 100644 --- a/src/contract_client/basic_node_signer.ts +++ b/src/soroban/contract_client/basic_node_signer.ts @@ -1,4 +1,4 @@ -import { Keypair, TransactionBuilder, hash } from ".."; +import { Keypair, TransactionBuilder, hash } from "@stellar/stellar-base"; import type { AssembledTransaction } from "./assembled_transaction"; import type { ContractClient } from "./client"; diff --git a/src/contract_client/client.ts b/src/soroban/contract_client/client.ts similarity index 95% rename from src/contract_client/client.ts rename to src/soroban/contract_client/client.ts index 7c8943bf3..a90edc5d1 100644 --- a/src/contract_client/client.ts +++ b/src/soroban/contract_client/client.ts @@ -1,4 +1,5 @@ -import { ContractSpec, xdr } from ".."; +import { xdr } from "@stellar/stellar-base"; +import { ContractSpec } from "../../contract_spec"; import { AssembledTransaction } from "./assembled_transaction"; import type { ContractClientOptions, MethodOptions } from "./types"; diff --git a/src/contract_client/index.ts b/src/soroban/contract_client/index.ts similarity index 85% rename from src/contract_client/index.ts rename to src/soroban/contract_client/index.ts index bd0c73fed..b9d7498cd 100644 --- a/src/contract_client/index.ts +++ b/src/soroban/contract_client/index.ts @@ -1,6 +1,7 @@ export * from "./assembled_transaction"; export * from "./basic_node_signer"; export * from "./client"; +export * from "./rust_result"; export * from "./sent_transaction"; export * from "./types"; export * from "./utils"; diff --git a/src/rust_types/result.ts b/src/soroban/contract_client/rust_result.ts similarity index 85% rename from src/rust_types/result.ts rename to src/soroban/contract_client/rust_result.ts index 8a47de4f4..b3c160851 100644 --- a/src/rust_types/result.ts +++ b/src/soroban/contract_client/rust_result.ts @@ -1,3 +1,6 @@ +/* disable max-classes rule, because extending error shouldn't count! */ +/* eslint max-classes-per-file: 0 */ + /** * A minimal implementation of Rust's `Result` type. Used for contract * methods that return Results, to maintain their distinction from methods @@ -52,10 +55,22 @@ export interface ErrorMessage { */ export class Ok implements Result { constructor(readonly value: T) {} - unwrapErr(): never { throw new Error("No error") } - unwrap() { return this.value } - isOk() { return true } - isErr() { return false } + + unwrapErr(): never { + throw new Error("No error"); + } + + unwrap() { + return this.value; + } + + isOk() { + return true; + } + + isErr() { + return false; + } } /** @@ -65,8 +80,20 @@ export class Ok implements Result { */ export class Err implements Result { constructor(readonly error: E) {} - unwrapErr() { return this.error } - unwrap(): never { throw new Error(this.error.message) } - isOk() { return false } - isErr() { return true } + + unwrapErr() { + return this.error; + } + + unwrap(): never { + throw new Error(this.error.message); + } + + isOk() { + return false; + } + + isErr() { + return true; + } } diff --git a/src/contract_client/sent_transaction.ts b/src/soroban/contract_client/sent_transaction.ts similarity index 92% rename from src/contract_client/sent_transaction.ts rename to src/soroban/contract_client/sent_transaction.ts index baa5e1f6f..f2c3974f3 100644 --- a/src/contract_client/sent_transaction.ts +++ b/src/soroban/contract_client/sent_transaction.ts @@ -1,7 +1,9 @@ /* disable max-classes rule, because extending error shouldn't count! */ /* eslint max-classes-per-file: 0 */ +import { SorobanDataBuilder, TransactionBuilder } from "@stellar/stellar-base"; import type { ContractClientOptions, MethodOptions, Tx } from "./types"; -import { SorobanDataBuilder, SorobanRpc, TransactionBuilder } from ".."; +import { Server } from "../server" +import { Api } from "../api" import { DEFAULT_TIMEOUT, withExponentialBackoff } from "./utils"; import type { AssembledTransaction } from "./assembled_transaction"; @@ -20,7 +22,7 @@ import type { AssembledTransaction } from "./assembled_transaction"; * `getTransactionResponse`. */ export class SentTransaction { - public server: SorobanRpc.Server; + public server: Server; public signed?: Tx; @@ -28,7 +30,7 @@ export class SentTransaction { * The result of calling `sendTransaction` to broadcast the transaction to the * network. */ - public sendTransactionResponse?: SorobanRpc.Api.SendTransactionResponse; + public sendTransactionResponse?: Api.SendTransactionResponse; /** * If `sendTransaction` completes successfully (which means it has `status: 'PENDING'`), @@ -36,13 +38,13 @@ export class SentTransaction { * {@link MethodOptions.timeoutInSeconds} seconds. This array contains all * the results of those calls. */ - public getTransactionResponseAll?: SorobanRpc.Api.GetTransactionResponse[]; + public getTransactionResponseAll?: Api.GetTransactionResponse[]; /** * The most recent result of calling `getTransaction`, from the * `getTransactionResponseAll` array. */ - public getTransactionResponse?: SorobanRpc.Api.GetTransactionResponse; + public getTransactionResponse?: Api.GetTransactionResponse; static Errors = { SendFailed: class SendFailedError extends Error { }, @@ -59,7 +61,7 @@ export class SentTransaction { "You must provide a `signTransaction` function to send a transaction", ); } - this.server = new SorobanRpc.Server(this.assembled.options.rpcUrl, { + this.server = new Server(this.assembled.options.rpcUrl, { allowHttp: this.assembled.options.allowHttp ?? false, }); } @@ -124,7 +126,7 @@ export class SentTransaction { this.getTransactionResponseAll = await withExponentialBackoff( () => this.server.getTransaction(hash), - (resp) => resp.status === SorobanRpc.Api.GetTransactionStatus.NOT_FOUND, + (resp) => resp.status === Api.GetTransactionStatus.NOT_FOUND, timeoutInSeconds, ); @@ -132,7 +134,7 @@ export class SentTransaction { this.getTransactionResponseAll[this.getTransactionResponseAll.length - 1]; if ( this.getTransactionResponse.status === - SorobanRpc.Api.GetTransactionStatus.NOT_FOUND + Api.GetTransactionStatus.NOT_FOUND ) { throw new SentTransaction.Errors.TransactionStillPending( `Waited ${timeoutInSeconds} seconds for transaction to complete, but it did not. ` + diff --git a/src/contract_client/types.ts b/src/soroban/contract_client/types.ts similarity index 99% rename from src/contract_client/types.ts rename to src/soroban/contract_client/types.ts index 5005d28c6..70c8b3b47 100644 --- a/src/contract_client/types.ts +++ b/src/soroban/contract_client/types.ts @@ -1,6 +1,6 @@ /* disable PascalCase naming convention, to avoid breaking change */ /* eslint-disable @typescript-eslint/naming-convention */ -import { BASE_FEE, Memo, MemoType, Operation, Transaction, xdr } from ".."; +import { BASE_FEE, Memo, MemoType, Operation, Transaction, xdr } from "@stellar/stellar-base"; import type { ContractClient } from "./client"; import type { AssembledTransaction } from "./assembled_transaction"; import { DEFAULT_TIMEOUT } from "./utils"; diff --git a/src/contract_client/utils.ts b/src/soroban/contract_client/utils.ts similarity index 100% rename from src/contract_client/utils.ts rename to src/soroban/contract_client/utils.ts diff --git a/src/soroban/index.ts b/src/soroban/index.ts index 36e296ee1..45702b70d 100644 --- a/src/soroban/index.ts +++ b/src/soroban/index.ts @@ -2,12 +2,13 @@ /// // Expose all types -export * from './api'; +export * from "./api"; // soroban-client classes to expose -export { Server, Durability } from './server'; -export { default as AxiosClient } from './axios'; -export { parseRawSimulation, parseRawEvents } from './parsers'; -export * from './transaction'; +export { Server, Durability } from "./server"; +export { default as AxiosClient } from "./axios"; +export { parseRawSimulation, parseRawEvents } from "./parsers"; +export * from "./transaction"; +export * as ContractClient from "./contract_client"; export default module.exports; diff --git a/test/e2e/src/test-custom-types.js b/test/e2e/src/test-custom-types.js index d31ad92aa..88ccdc703 100644 --- a/test/e2e/src/test-custom-types.js +++ b/test/e2e/src/test-custom-types.js @@ -1,8 +1,9 @@ const test = require('ava') -const { Address } = require('../../..') -const { Ok, Err } = require('../../../lib/rust_types') +const { Address, SorobanRpc } = require('../../..') const { clientFor } = require('./util') +const { Ok, Err } = SorobanRpc.ContractClient + test.before(async t => { const { client, keypair, contractId } = await clientFor('customTypes') const publicKey = keypair.publicKey() diff --git a/test/e2e/src/test-hello-world.js b/test/e2e/src/test-hello-world.js index a489f1692..fbd927be3 100644 --- a/test/e2e/src/test-hello-world.js +++ b/test/e2e/src/test-hello-world.js @@ -1,6 +1,5 @@ const test = require('ava') const { clientFor } = require('./util') -const { Keypair } = require('../../..') test("hello", async (t) => { const { client } = await clientFor('helloWorld') diff --git a/test/e2e/src/test-swap.js b/test/e2e/src/test-swap.js index 802ed0d73..d36f698f5 100644 --- a/test/e2e/src/test-swap.js +++ b/test/e2e/src/test-swap.js @@ -1,8 +1,9 @@ const test = require('ava') const { SorobanRpc } = require('../../..') -const { AssembledTransaction } = require('../../../lib/contract_client') const { clientFor, generateFundedKeypair } = require('./util') +const { AssembledTransaction } = SorobanRpc.ContractClient + const amountAToSwap = 2n const amountBToSwap = 1n diff --git a/test/e2e/src/util.js b/test/e2e/src/util.js index 3aaeb91f9..a7d1e731c 100644 --- a/test/e2e/src/util.js +++ b/test/e2e/src/util.js @@ -1,9 +1,9 @@ const { spawnSync } = require('node:child_process') -const { ContractSpec, Keypair } = require('../../..') +const { ContractSpec, Keypair, SorobanRpc } = require('../../..') const { ContractClient, basicNodeSigner, -} = require('../../../lib/contract_client') +} = SorobanRpc.ContractClient const contracts = { customTypes: {