-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore/change to non dir imports (#24)
* chore: change to non dir imports * chore: bump version * chore: fix dir imports * chore: bump version
- Loading branch information
Showing
4 changed files
with
27 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,39 @@ | ||
// Copyright 2020-2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { | ||
IotaDID, | ||
IotaDocument, | ||
IotaIdentityClient, | ||
JwkMemStore, | ||
JwsAlgorithm, | ||
KeyIdMemStore, | ||
MethodScope, | ||
Storage, | ||
Credential, | ||
JwsSignatureOptions, | ||
} from "@iota/identity-wasm/node"; | ||
import { | ||
AliasOutput, | ||
Client, | ||
IOutputsResponse, | ||
MnemonicSecretManager, | ||
SecretManager, | ||
SeedSecretManager, | ||
Utils, | ||
} from "@iota/sdk-wasm/node"; | ||
import { Client, IOutputsResponse } from "@iota/sdk-wasm/node/lib/index.js"; | ||
import { InsufficientBalanceError } from "./errors/BalanceErorr"; | ||
|
||
export async function ensureAddressHasFunds( | ||
client: Client, | ||
addressBech32: string, | ||
amount: string, | ||
seed: string | ||
client: Client, | ||
addressBech32: string, | ||
amount: string, | ||
seed: string | ||
) { | ||
let balance = await getAddressBalance(client, addressBech32); | ||
if (balance >= BigInt(amount)) { | ||
return; | ||
} | ||
throw new InsufficientBalanceError(addressBech32, parseInt(amount), seed); | ||
let balance = await getAddressBalance(client, addressBech32); | ||
if (balance >= BigInt(amount)) { | ||
return; | ||
} | ||
throw new InsufficientBalanceError(addressBech32, parseInt(amount), seed); | ||
} | ||
|
||
/** Returns the balance of the given Bech32-encoded address. */ | ||
async function getAddressBalance( | ||
client: Client, | ||
addressBech32: string | ||
client: Client, | ||
addressBech32: string | ||
): Promise<bigint> { | ||
const outputIds: IOutputsResponse = await client.basicOutputIds([ | ||
{ address: addressBech32 }, | ||
{ hasExpiration: false }, | ||
{ hasTimelock: false }, | ||
{ hasStorageDepositReturn: false }, | ||
]); | ||
const outputs = await client.getOutputs(outputIds.items); | ||
const outputIds: IOutputsResponse = await client.basicOutputIds([ | ||
{ address: addressBech32 }, | ||
{ hasExpiration: false }, | ||
{ hasTimelock: false }, | ||
{ hasStorageDepositReturn: false }, | ||
]); | ||
const outputs = await client.getOutputs(outputIds.items); | ||
|
||
let totalAmount = BigInt(0); | ||
for (const output of outputs) { | ||
totalAmount += output.output.getAmount(); | ||
} | ||
let totalAmount = BigInt(0); | ||
for (const output of outputs) { | ||
totalAmount += output.output.getAmount(); | ||
} | ||
|
||
return totalAmount; | ||
return totalAmount; | ||
} |