Skip to content

Commit 139370e

Browse files
committed
add few more wrappers
1 parent ccbcc99 commit 139370e

File tree

1 file changed

+80
-2
lines changed

1 file changed

+80
-2
lines changed

src/utils/cspr-network.ts

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
NativeTransferBuilder,
1616
NativeUndelegateBuilder,
1717
PublicKey,
18+
SessionBuilder,
1819
Transaction,
1920
TransactionHash
2021
} from '../types';
@@ -197,6 +198,80 @@ export class CasperNetwork {
197198
return transferBuilder.buildFor1_5();
198199
}
199200

201+
public createContractCallTransaction(
202+
senderPublicKey: PublicKey,
203+
contractHash: string,
204+
entryPoint: string,
205+
networkName: string,
206+
deployCost: number,
207+
ttl: number,
208+
args: Args
209+
): Transaction {
210+
const contractCall = new ContractCallBuilder()
211+
.byHash(contractHash)
212+
.from(senderPublicKey)
213+
.entryPoint(entryPoint)
214+
.chainName(networkName)
215+
.runtimeArgs(args)
216+
.ttl(ttl)
217+
.payment(deployCost);
218+
219+
if (this.apiVersion === 2) {
220+
return contractCall.build();
221+
}
222+
223+
return contractCall.buildFor1_5();
224+
}
225+
226+
public createContractPackageTransaction(
227+
senderPublicKey: PublicKey,
228+
contractPackageHash: string,
229+
entryPoint: string,
230+
networkName: string,
231+
deployCost: number,
232+
args: Args,
233+
ttl: number,
234+
contractVersion?: number
235+
): Transaction {
236+
const contractCall = new ContractCallBuilder()
237+
.byPackageHash(contractPackageHash, contractVersion)
238+
.from(senderPublicKey)
239+
.entryPoint(entryPoint)
240+
.chainName(networkName)
241+
.runtimeArgs(args)
242+
.ttl(ttl)
243+
.payment(deployCost);
244+
245+
if (this.apiVersion === 2) {
246+
return contractCall.build();
247+
}
248+
249+
return contractCall.buildFor1_5();
250+
}
251+
252+
public createSessionWasmTransaction(
253+
senderPublicKey: PublicKey,
254+
networkName: string,
255+
deployCost: number,
256+
ttl: number,
257+
bytes: Uint8Array,
258+
args: Args
259+
): Transaction {
260+
const sessionWasm = new SessionBuilder()
261+
.from(senderPublicKey)
262+
.chainName(networkName)
263+
.payment(deployCost)
264+
.ttl(ttl)
265+
.wasm(bytes)
266+
.runtimeArgs(args);
267+
268+
if (this.apiVersion === 2) {
269+
return sessionWasm.build();
270+
}
271+
272+
return sessionWasm.buildFor1_5();
273+
}
274+
200275
public async putTransaction(
201276
transaction: Transaction
202277
): Promise<PutTransactionResult | PutDeployResult> {
@@ -216,7 +291,7 @@ export class CasperNetwork {
216291

217292
public async getTransaction(
218293
hash: TransactionHash
219-
): Promise<InfoGetTransactionResult | InfoGetDeployResult> {
294+
): Promise<InfoGetTransactionResult> {
220295
if (this.apiVersion == 2) {
221296
if (hash.transactionV1) {
222297
return await this.rpcClient.getTransactionByTransactionHash(
@@ -232,7 +307,10 @@ export class CasperNetwork {
232307
}
233308

234309
if (hash.deploy) {
235-
return await this.rpcClient.getDeploy(hash.deploy.toHex());
310+
const getDeployResult = await this.rpcClient.getDeploy(
311+
hash.deploy.toHex()
312+
);
313+
return getDeployResult.toInfoGetTransactionResult();
236314
}
237315

238316
return Promise.reject('Hash is not valid');

0 commit comments

Comments
 (0)