1- import {
2- Operation ,
3- xdr ,
4- Address ,
5- } from "@stellar/stellar-base" ;
1+ import { Operation , xdr , Address } from "@stellar/stellar-base" ;
62import { Spec } from "./spec" ;
7- import { Server } from ' ../rpc' ;
3+ import { Server } from " ../rpc" ;
84import { AssembledTransaction } from "./assembled_transaction" ;
95import type { ClientOptions , MethodOptions } from "./types" ;
106
@@ -13,7 +9,7 @@ const CONSTRUCTOR_FUNC = "__constructor";
139async function specFromWasmHash (
1410 wasmHash : Buffer | string ,
1511 options : Server . Options & { rpcUrl : string } ,
16- format : "hex" | "base64" = "hex"
12+ format : "hex" | "base64" = "hex" ,
1713) : Promise < Spec > {
1814 if ( ! options || ! options . rpcUrl ) {
1915 throw new TypeError ( "options must contain rpcUrl" ) ;
@@ -54,20 +50,29 @@ export class Client {
5450 format ?: "hex" | "base64" ;
5551 /** The address to use to deploy the custom contract */
5652 address ?: string ;
57- }
53+ } ,
5854 ) : Promise < AssembledTransaction < T > > {
59- const { wasmHash, salt, format, fee, timeoutInSeconds, simulate, ...clientOptions } = options ;
55+ const {
56+ wasmHash,
57+ salt,
58+ format,
59+ fee,
60+ timeoutInSeconds,
61+ simulate,
62+ ...clientOptions
63+ } = options ;
6064 const spec = await specFromWasmHash ( wasmHash , clientOptions , format ) ;
6165
6266 const operation = Operation . createCustomContract ( {
6367 address : new Address ( options . address || options . publicKey ! ) ,
64- wasmHash : typeof wasmHash === "string"
65- ? Buffer . from ( wasmHash , format ?? "hex" )
66- : ( wasmHash as Buffer ) ,
68+ wasmHash :
69+ typeof wasmHash === "string"
70+ ? Buffer . from ( wasmHash , format ?? "hex" )
71+ : ( wasmHash as Buffer ) ,
6772 salt,
6873 constructorArgs : args
6974 ? spec . funcArgsToScVals ( CONSTRUCTOR_FUNC , args )
70- : [ ]
75+ : [ ] ,
7176 } ) ;
7277
7378 return AssembledTransaction . buildWithOp ( operation , {
@@ -78,13 +83,16 @@ export class Client {
7883 contractId : "ignored" ,
7984 method : CONSTRUCTOR_FUNC ,
8085 parseResultXdr : ( result ) =>
81- new Client ( spec , { ...clientOptions , contractId : Address . fromScVal ( result ) . toString ( ) } )
86+ new Client ( spec , {
87+ ...clientOptions ,
88+ contractId : Address . fromScVal ( result ) . toString ( ) ,
89+ } ) ,
8290 } ) as unknown as AssembledTransaction < T > ;
8391 }
8492
8593 constructor (
8694 public readonly spec : Spec ,
87- public readonly options : ClientOptions
95+ public readonly options : ClientOptions ,
8896 ) {
8997 this . spec . funcs ( ) . forEach ( ( xdrFn ) => {
9098 const method = xdrFn . name ( ) . toString ( ) ;
@@ -93,7 +101,7 @@ export class Client {
93101 }
94102 const assembleTransaction = (
95103 args ?: Record < string , any > ,
96- methodOptions ?: MethodOptions
104+ methodOptions ?: MethodOptions ,
97105 ) =>
98106 AssembledTransaction . build ( {
99107 method,
@@ -129,12 +137,13 @@ export class Client {
129137 * @returns {Promise<module:contract.Client> } A Promise that resolves to a Client instance.
130138 * @throws {TypeError } If the provided options object does not contain an rpcUrl.
131139 */
132- static async fromWasmHash ( wasmHash : Buffer | string ,
140+ static async fromWasmHash (
141+ wasmHash : Buffer | string ,
133142 options : ClientOptions ,
134- format : "hex" | "base64" = "hex"
143+ format : "hex" | "base64" = "hex" ,
135144 ) : Promise < Client > {
136145 if ( ! options || ! options . rpcUrl ) {
137- throw new TypeError ( ' options must contain rpcUrl' ) ;
146+ throw new TypeError ( " options must contain rpcUrl" ) ;
138147 }
139148 const { rpcUrl, allowHttp } = options ;
140149 const serverOpts : Server . Options = { allowHttp } ;
@@ -165,7 +174,7 @@ export class Client {
165174 */
166175 static async from ( options : ClientOptions ) : Promise < Client > {
167176 if ( ! options || ! options . rpcUrl || ! options . contractId ) {
168- throw new TypeError ( ' options must contain rpcUrl and contractId' ) ;
177+ throw new TypeError ( " options must contain rpcUrl and contractId" ) ;
169178 }
170179 const { rpcUrl, contractId, allowHttp } = options ;
171180 const serverOpts : Server . Options = { allowHttp } ;
@@ -187,5 +196,6 @@ export class Client {
187196 ) ;
188197 } ;
189198
190- txFromXDR = < T > ( xdrBase64 : string ) : AssembledTransaction < T > => AssembledTransaction . fromXDR ( this . options , xdrBase64 , this . spec ) ;
199+ txFromXDR = < T > ( xdrBase64 : string ) : AssembledTransaction < T > =>
200+ AssembledTransaction . fromXDR ( this . options , xdrBase64 , this . spec ) ;
191201}
0 commit comments