Skip to content

Commit 2c766e5

Browse files
authored
Src folder formatting (#1222)
* chore: add setup/postinstall scripts for blame ignore and remove parser option in prettier config for ts fmting * chore: add formatting to src folder via prettier config * chore: add commit hash for mass prettier fmting * chore: fmt
1 parent add216d commit 2c766e5

43 files changed

Lines changed: 1024 additions & 762 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.git-blame-ignore-revs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
030c448da30ff159419dcc92e2921ef578cca426

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ js-stellar-base/
1212

1313
test/unit/out/
1414
.vscode/launch.json
15-
15+
.vscode
1616
target
1717
.soroban
1818

config/prettier.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ module.exports = {
55
printWidth: 80,
66
proseWrap: 'always',
77
semi: true,
8-
singleQuote: true,
8+
singleQuote: false,
99
tabWidth: 2,
10-
parser: 'babel',
11-
trailingComma: 'none',
10+
trailingComma: 'all',
1211
useTabs: false
1312
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
}
7979
},
8080
"scripts": {
81+
"setup": "git config blame.ignoreRevsFile .git-blame-ignore-revs",
82+
"postinstall": "yarn setup || true",
8183
"build": "cross-env NODE_ENV=development yarn _build",
8284
"build:prod": "cross-env NODE_ENV=production yarn _build",
8385
"build:node": "yarn _babel && yarn build:ts",
@@ -109,7 +111,7 @@
109111
"_build": "yarn build:node:all && yarn build:test && yarn build:browser:all",
110112
"_babel": "babel --extensions '.ts' --out-dir ${OUTPUT_DIR:-lib} src/",
111113
"_nyc": "node node_modules/.bin/nyc --nycrc-path config/.nycrc",
112-
"_prettier": "prettier --ignore-path config/.prettierignore --write './test/**/*.js'"
114+
"_prettier": "prettier --config config/prettier.config.js --ignore-path config/.prettierignore --write './src/**/*.ts' './test/**/*.js'"
113115
},
114116
"husky": {
115117
"hooks": {

src/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const defaultConfig: Configuration = {
1919
timeout: 0,
2020
};
2121

22-
let config = { ...defaultConfig};
22+
let config = { ...defaultConfig };
2323

2424
/**
2525
* Global config class.
@@ -80,7 +80,7 @@ class Config {
8080
* @static
8181
*/
8282
public static setDefault(): void {
83-
config = { ...defaultConfig};
83+
config = { ...defaultConfig };
8484
}
8585
}
8686

src/contract/basic_node_signer.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ export const basicNodeSigner = (
2323
} => ({
2424
// eslint-disable-next-line require-await
2525
signTransaction: async (xdr, opts) => {
26-
const t = TransactionBuilder.fromXDR(xdr, opts?.networkPassphrase || networkPassphrase);
26+
const t = TransactionBuilder.fromXDR(
27+
xdr,
28+
opts?.networkPassphrase || networkPassphrase,
29+
);
2730
t.sign(keypair);
2831
return {
2932
signedTxXdr: t.toXDR(),
@@ -32,10 +35,12 @@ export const basicNodeSigner = (
3235
},
3336
// eslint-disable-next-line require-await
3437
signAuthEntry: async (authEntry) => {
35-
const signedAuthEntry = keypair.sign(hash(Buffer.from(authEntry, "base64"))).toString("base64");
38+
const signedAuthEntry = keypair
39+
.sign(hash(Buffer.from(authEntry, "base64")))
40+
.toString("base64");
3641
return {
3742
signedAuthEntry,
3843
signerAddress: keypair.publicKey(),
3944
};
4045
},
41-
});
46+
});

src/contract/client.ts

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import {
2-
Operation,
3-
xdr,
4-
Address,
5-
} from "@stellar/stellar-base";
1+
import { Operation, xdr, Address } from "@stellar/stellar-base";
62
import { Spec } from "./spec";
7-
import { Server } from '../rpc';
3+
import { Server } from "../rpc";
84
import { AssembledTransaction } from "./assembled_transaction";
95
import type { ClientOptions, MethodOptions } from "./types";
106

@@ -13,7 +9,7 @@ const CONSTRUCTOR_FUNC = "__constructor";
139
async 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
}

src/contract/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ export * from "./client";
44
export * from "./rust_result";
55
export * from "./sent_transaction";
66
export * from "./spec";
7-
export * from "./types";
7+
export * from "./types";

src/contract/spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
Address,
77
Contract,
88
scValToBigInt,
9-
} from "@stellar/stellar-base"
10-
import { Ok } from "./rust_result"
11-
import { specFromWasm, processSpecEntryStream } from './utils';
9+
} from "@stellar/stellar-base";
10+
import { Ok } from "./rust_result";
11+
import { specFromWasm, processSpecEntryStream } from "./utils";
1212

1313
export interface Union<T> {
1414
tag: string;
@@ -434,7 +434,6 @@ function unionToJsonSchema(udt: xdr.ScSpecUdtUnionV0): any {
434434
}
435435
/* eslint-enable default-case */
436436

437-
438437
/**
439438
* Provides a ContractSpec class which can contains the XDR types defined by the contract.
440439
* This allows the class to be used to convert between native and raw `xdr.ScVal`s.
@@ -623,7 +622,6 @@ export class Spec {
623622
return entry;
624623
}
625624

626-
627625
/**
628626
* Converts a native JS value to an ScVal based on the given type.
629627
*
@@ -765,7 +763,8 @@ export class Spec {
765763

766764
if ((val.constructor?.name ?? "") !== "Object") {
767765
throw new TypeError(
768-
`cannot interpret ${val.constructor?.name
766+
`cannot interpret ${
767+
val.constructor?.name
769768
} value as ScVal (${JSON.stringify(val)})`,
770769
);
771770
}
@@ -968,7 +967,8 @@ export class Spec {
968967
return (scv.vec() ?? []).map((elm) =>
969968
this.scValToNative(elm, vec.elementType()),
970969
) as T;
971-
} if (value === xdr.ScSpecType.scSpecTypeTuple().value) {
970+
}
971+
if (value === xdr.ScSpecType.scSpecTypeTuple().value) {
972972
const tuple = typeDef.tuple();
973973
const valTypes = tuple.valueTypes();
974974
return (scv.vec() ?? []).map((elm, i) =>
@@ -1016,7 +1016,8 @@ export class Spec {
10161016
value !== xdr.ScSpecType.scSpecTypeSymbol().value
10171017
) {
10181018
throw new Error(
1019-
`ScSpecType ${t.name
1019+
`ScSpecType ${
1020+
t.name
10201021
} was not string or symbol, but ${JSON.stringify(scv, null, 2)} is`,
10211022
);
10221023
}
@@ -1146,7 +1147,7 @@ export class Spec {
11461147
jsonSchema(funcName?: string): JSONSchema7 {
11471148
const definitions: { [key: string]: JSONSchema7Definition } = {};
11481149
/* eslint-disable default-case */
1149-
this.entries.forEach(entry => {
1150+
this.entries.forEach((entry) => {
11501151
switch (entry.switch().value) {
11511152
case xdr.ScSpecEntryKind.scSpecEntryUdtEnumV0().value: {
11521153
const udt = entry.udtEnumV0();

src/contract/types.ts

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
/* disable PascalCase naming convention, to avoid breaking change */
22
/* eslint-disable @typescript-eslint/naming-convention */
3-
import { Memo, MemoType, Operation, Transaction, xdr } from "@stellar/stellar-base";
3+
import {
4+
Memo,
5+
MemoType,
6+
Operation,
7+
Transaction,
8+
xdr,
9+
} from "@stellar/stellar-base";
410
import type { Client } from "./client";
511

612
export type XDR_BASE64 = string;
@@ -63,9 +69,9 @@ export interface WalletError {
6369

6470
/**
6571
* A function to request a wallet to sign a built transaction
66-
*
72+
*
6773
* This function takes an XDR provided by the requester and applies a signature to it.
68-
* It returns a base64-encoded string XDR-encoded Transaction Envelope with Decorated Signatures
74+
* It returns a base64-encoded string XDR-encoded Transaction Envelope with Decorated Signatures
6975
* and the signer address back to the requester.
7076
*
7177
* @param xdr - The XDR string representing the transaction to be signed.
@@ -77,20 +83,25 @@ export interface WalletError {
7783
*
7884
* @returns A promise resolving to an object with the signed transaction XDR and optional signer address and error.
7985
*/
80-
export type SignTransaction = (xdr: string, opts?: {
81-
networkPassphrase?: string;
82-
address?: string;
83-
submit?: boolean;
84-
submitUrl?: string;
85-
}) => Promise<{
86-
signedTxXdr: string;
87-
signerAddress?: string;
88-
} & { error?: WalletError }>;
86+
export type SignTransaction = (
87+
xdr: string,
88+
opts?: {
89+
networkPassphrase?: string;
90+
address?: string;
91+
submit?: boolean;
92+
submitUrl?: string;
93+
},
94+
) => Promise<
95+
{
96+
signedTxXdr: string;
97+
signerAddress?: string;
98+
} & { error?: WalletError }
99+
>;
89100

90101
/**
91102
* A function to request a wallet to sign an authorization entry preimage.
92103
*
93-
* Similar to signing a transaction, this function takes an authorization entry preimage provided by the
104+
* Similar to signing a transaction, this function takes an authorization entry preimage provided by the
94105
* requester and applies a signature to it.
95106
* It returns a signed hash of the same authorization entry and the signer address back to the requester.
96107
*
@@ -101,13 +112,18 @@ export type SignTransaction = (xdr: string, opts?: {
101112
*
102113
* @returns A promise resolving to an object with the signed authorization entry and optional signer address and error.
103114
*/
104-
export type SignAuthEntry = (authEntry: string, opts?: {
105-
networkPassphrase?: string;
106-
address?: string;
107-
}) => Promise<{
108-
signedAuthEntry: string;
109-
signerAddress?: string;
110-
} & { error?: WalletError }>;
115+
export type SignAuthEntry = (
116+
authEntry: string,
117+
opts?: {
118+
networkPassphrase?: string;
119+
address?: string;
120+
},
121+
) => Promise<
122+
{
123+
signedAuthEntry: string;
124+
signerAddress?: string;
125+
} & { error?: WalletError }
126+
>;
111127

112128
/**
113129
* Options for a smart contract client.
@@ -255,4 +271,5 @@ export const DEFAULT_TIMEOUT = 5 * 60;
255271
* @default GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF
256272
* @memberof module:contract
257273
*/
258-
export const NULL_ACCOUNT = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF";
274+
export const NULL_ACCOUNT =
275+
"GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF";

0 commit comments

Comments
 (0)