Skip to content

Commit

Permalink
Chore/bindings: cleanup is alive 2.0 (#1541)
Browse files Browse the repository at this point in the history
* simplify nodejs client and wallet

* got -> was

* fixed client on node side

* wasm

* removed await for client

* lint n format

* fixed test and client error return

* fixed error and comment

* Simplify nodejs and wasm bindings p. 2 (#1146)

* unify error handling and responses

* wasm

* its something

* secret manager alignment

* error on callback fix

* listen error in wasm, madelisten async again

* final changes

* removed unused PromiseString

* lint

* wasm update

* nodejs

* removed async closure

* nodejs fixed with tests

* fmt

* some fixes

* mqtt

* rewrite again eh :D

* client.create()

* format and fmt

* review and 8050

* typo

* updated error handling in nodejs once again

* wasm destroy rename

* Update bindings/nodejs/lib/index.ts

Co-authored-by: DaughterOfMars <[email protected]>

* secret manager create

* typo grrr

* forgot to rename create methods

* Done more comment explaining :D

* removed mqtt custom serde

* wasm fixes

* fix tests

* fmt

* fixed secret

* promise await

* fixed errors, separate eslint

* wasm side

* typo

---------

Co-authored-by: Alex Coats <[email protected]>
Co-authored-by: Thibault Martinez <[email protected]>
Co-authored-by: /alex/ <[email protected]>
Co-authored-by: Thoralf-M <[email protected]>
  • Loading branch information
5 people committed Dec 13, 2023
1 parent 1b97256 commit 51011bd
Show file tree
Hide file tree
Showing 115 changed files with 964 additions and 673 deletions.
6 changes: 3 additions & 3 deletions bindings/core/tests/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn create_wallet() -> Result<()> {
let client_options = r#"{
"nodes":[
{
"url":"http://localhost:14265",
"url":"http://localhost:8050",
"auth":null,
"disabled":false
}
Expand Down Expand Up @@ -70,7 +70,7 @@ async fn client_from_wallet() -> Result<()> {
let client_options = r#"{
"nodes":[
{
"url":"http://localhost:14265",
"url":"http://localhost:8050",
"auth":null,
"disabled":false
}
Expand Down Expand Up @@ -112,7 +112,7 @@ async fn client_from_wallet() -> Result<()> {
// "about solution utility exist rail budget vacuum major survey clerk pave ankle wealth gym gossip still medal
// expect strong rely amazing inspire lazy lunar", ).unwrap();
// let client = ClientBuilder::default()
// .with_nodes(&["http://localhost:14265"])
// .with_nodes(&["http://localhost:8050"])
// .unwrap()
// .finish()
// .await
Expand Down
4 changes: 3 additions & 1 deletion bindings/nodejs/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ target
**/node_modules/
**/out/
**/tests/
**/dist
**/dist
jest.config.js
.eslintrc.js
2 changes: 2 additions & 0 deletions bindings/nodejs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const typescriptEslintRules = {
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-var-requires': 'off', // cleanest way to set dotenv path
'@typescript-eslint/no-explicit-any': 'off',
"@typescript-eslint/no-floating-promises": ["error"],
};

module.exports = {
Expand All @@ -24,6 +25,7 @@ module.exports = {
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
project: ["./tsconfig.eslint.json"],
},
rules: typescriptEslintRules,
};
4 changes: 2 additions & 2 deletions bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const { Client, initLogger } = require('@iota/sdk');
async function run() {
initLogger();

const client = new Client({
const client = await Client.create({
nodes: ['https://api.testnet.shimmer.network'],
});

Expand All @@ -102,7 +102,7 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
```

## Wallet Usage
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/04-get-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand All @@ -30,4 +30,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/client/05-get-address-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});

try {
const secretManager = new SecretManager({
const secretManager = SecretManager.create({
mnemonic: process.env.MNEMONIC as string,
});

Expand Down Expand Up @@ -75,4 +75,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/client/06-simple-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ async function run() {
mnemonic: process.env.MNEMONIC,
};

const secretManager = new SecretManager(mnemonicSecretManager);
const secretManager = SecretManager.create(mnemonicSecretManager);

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand Down Expand Up @@ -67,4 +67,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/07-get-block-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand All @@ -38,4 +38,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/client/08-data-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ async function run() {
mnemonic: process.env.MNEMONIC,
};

const secretManager = new SecretManager(mnemonicSecretManager);
const secretManager = SecretManager.create(mnemonicSecretManager);

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand Down Expand Up @@ -75,4 +75,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/10-mqtt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function run() {
}

// Connecting to a MQTT broker using raw ip doesn't work with TCP. This is a limitation of rustls.
const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand Down Expand Up @@ -55,4 +55,4 @@ async function run() {
}, 10000);
}

run();
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/11-build-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand Down Expand Up @@ -121,4 +121,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/12-get-raw-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand All @@ -32,4 +32,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/13-build-account-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand Down Expand Up @@ -59,4 +59,4 @@ async function run() {
}
}

run();
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/14-build-foundry-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand Down Expand Up @@ -53,4 +53,4 @@ async function run() {
}
}

run();
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/15-build-nft-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand Down Expand Up @@ -68,4 +68,4 @@ async function run() {
}
}

run();
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/16-custom-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function run() {
}
}

const client = new Client({
const client = await Client.create({
// Insert your node URL in the .env.
nodes: [process.env.NODE_URL as string],
});
Expand All @@ -41,4 +41,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/client/getting-started.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Client } from '@iota/sdk';

// In this example we will get information about the node
async function run() {
const client = new Client({
const client = await Client.create({
nodes: ['https://api.testnet.shimmer.network'],
});

Expand All @@ -20,4 +20,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
4 changes: 2 additions & 2 deletions bindings/nodejs/examples/evm/send-evm-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function run(): Promise<void> {
mnemonic: process.env.MNEMONIC as string,
};

const secretManager = new SecretManager(mnemonicSecretManager);
const secretManager = SecretManager.create(mnemonicSecretManager);

const addresses = await secretManager.generateEvmAddresses({
coinType: ETHEREUM_COIN_TYPE,
Expand Down Expand Up @@ -170,4 +170,4 @@ function padHexString(str: string): string {
return str.length % 2 !== 0 ? '0' + str : str;
}

run();
void run().then(() => process.exit());
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/0-generate-mnemonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
6 changes: 3 additions & 3 deletions bindings/nodejs/examples/exchange/1-create-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function run() {
},
};

const secretManager = new SecretManager(strongholdSecretManager);
const secretManager = SecretManager.create(strongholdSecretManager);

// A mnemonic can be generated with `Utils.generateMnemonic()`.
// Store the mnemonic in the Stronghold snapshot, this needs to be done only the first time.
Expand Down Expand Up @@ -65,10 +65,10 @@ async function run() {

// Set syncOnlyMostBasicOutputs to true if not interested in outputs that are timelocked,
// have a storage deposit return, expiration or are nft/account/foundry outputs.
wallet.setDefaultSyncOptions({ syncOnlyMostBasicOutputs: true });
await wallet.setDefaultSyncOptions({ syncOnlyMostBasicOutputs: true });
} catch (error) {
console.error(error);
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/3-check-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/4-listen-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/exchange/5-send-amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/how_tos/account_output/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ async function run() {
process.exit(0);
}

run();
void run().then(() => process.exit());
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/how_tos/account_output/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ async function run() {
process.exit(0);
}

run();
void run().then(() => process.exit());
15 changes: 9 additions & 6 deletions bindings/nodejs/examples/how_tos/account_wallet/request-funds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ async function run() {
const wallet = await Wallet.create({
storagePath: process.env.WALLET_DB_PATH,
});

const balance = await wallet.sync();

const totalBaseTokenBalance = balance.baseCoin.total;
Expand All @@ -39,14 +38,18 @@ async function run() {
const accountId = balance.accounts[0];
console.log(`Account Id: ${accountId}`);

const client = await wallet.getClient();

// Get Account address
const accountAddress = Utils.accountIdToBech32(
accountId,
await (await wallet.getClient()).getBech32Hrp(),
await client.getBech32Hrp(),
);

const faucetResponse = await client.requestFundsFromFaucet(
faucetUrl,
accountAddress,
);
const faucetResponse = await (
await wallet.getClient()
).requestFundsFromFaucet(faucetUrl, accountAddress);
console.log(faucetResponse);

await new Promise((resolve) => setTimeout(resolve, 10000));
Expand All @@ -66,4 +69,4 @@ async function run() {
}
}

run().then(() => process.exit());
void run().then(() => process.exit());
Loading

0 comments on commit 51011bd

Please sign in to comment.