Skip to content

Commit

Permalink
Moves ContractSpec jsdoc into the right place to render (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Sep 11, 2023
1 parent 4b77acf commit ec9f602
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions src/contract_spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { ScIntType, XdrLargeInt, xdr } from "stellar-base";

import { Address } from "stellar-base";
import { Contract } from "stellar-base";
import { scValToBigInt } from "stellar-base";

export interface Union<T> {
tag: string;
values?: T;
}

/**
* Provides a ContractSpec class which can contains the XDR types defined by the contract.
* This allows the class to be used to convert between native and raw `xdr.ScVal`s.
*
* @example
* ```js
* const specEntries = [...]; // XDR spec entries of a smart contract
* const contractSpec = new ContractSpec(specEntries);
*
Expand All @@ -21,29 +31,7 @@
* const result = contractSpec.funcResToNative('funcName', resultScv);
*
* console.log(result); // {success: true}
* ```
*/

import { ScIntType, XdrLargeInt, xdr } from "stellar-base";

import { Address } from "stellar-base";
import { Contract } from "stellar-base";
import { scValToBigInt } from "stellar-base";

export interface Union<T> {
tag: string;
values?: T;
}

function readObj(args: object, input: xdr.ScSpecFunctionInputV0): any {
let inputName = input.name().toString();
let entry = Object.entries(args).find(([name, _]) => name === inputName);
if (!entry) {
throw new Error(`Missing field ${inputName}`);
}
return entry[1];
}

export class ContractSpec {
public entries: xdr.ScSpecEntry[] = [];

Expand Down Expand Up @@ -694,3 +682,12 @@ function findCase(name: string) {
}
};
}

function readObj(args: object, input: xdr.ScSpecFunctionInputV0): any {
let inputName = input.name().toString();
let entry = Object.entries(args).find(([name, _]) => name === inputName);
if (!entry) {
throw new Error(`Missing field ${inputName}`);
}
return entry[1];
}

0 comments on commit ec9f602

Please sign in to comment.