Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing binding methods #1

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function validateTypes(values, expectedTypes) {
exports.AssetSchema = AssetSchema = {
Nia: "Nia",
Cfa: "Cfa",
Uda: "Uda",
};

exports.BitcoinNetwork = BitcoinNetwork = {
Expand Down Expand Up @@ -126,6 +127,17 @@ exports.generateKeys = function generateKeys(bitcoinNetwork) {
return JSON.parse(lib.rgblib_generate_keys(bitcoinNetwork));
};

exports.restoreKeys = function (bitcoinNetwork, mnemonic) {
validateEnumValues(
{ bitcoinNetwork },
{
bitcoinNetwork: BitcoinNetwork,
},
);
validateTypes({ mnemonic }, { mnemonic: "string" });
return JSON.parse(lib.rgblib_restore_keys(bitcoinNetwork, mnemonic));
tmalahie marked this conversation as resolved.
Show resolved Hide resolved
};

exports.WalletData = class WalletData {
constructor(walletData) {
validateProperties(walletData, [
Expand Down Expand Up @@ -233,6 +245,61 @@ exports.Wallet = class Wallet {
return lib.rgblib_get_address(this.wallet);
}

getBtcBalance(online, skipSync) {
const params = { online, skipSync };
const expectedTypes = {
online: "object",
skipSync: "boolean",
};
validateTypes(params, expectedTypes);
return JSON.parse(lib.rgblib_get_btc_balance(this.wallet, online, skipSync));
}

getAssetBalance(assetId) {
const params = { assetId };
const expectedTypes = {
assetId: "string",
};
validateTypes(params, expectedTypes);
return JSON.parse(lib.rgblib_get_asset_balance(this.wallet, assetId));
}

listTransactions(online, skipSync) {
const params = { online, skipSync };
const expectedTypes = {
online: "object",
skipSync: "boolean",
};
validateTypes(params, expectedTypes);
return JSON.parse(lib.rgblib_list_transactions(this.wallet, online, skipSync));
}

sendBtc(online, address, amount, feeRate, skipSync) {
const params = {
online,
address,
amount,
feeRate,
skipSync,
};
const expectedTypes = {
online: "object",
address: "string",
amount: "u64",
feeRate: "f32",
skipSync: "boolean",
};
validateTypes(params, expectedTypes);
return lib.rgblib_send_btc(
this.wallet,
online,
address,
amount,
feeRate,
skipSync,
);
}

goOnline(skipConsistencyCheck, electrumUrl) {
const params = { skipConsistencyCheck, electrumUrl };
const expectedTypes = {
Expand Down Expand Up @@ -363,6 +430,34 @@ exports.Wallet = class Wallet {
);
}

listTransfers(assetId) {
const params = {
assetId,
};
const expectedTypes = {
assetId: "string",
};
validateTypes(params, expectedTypes);
return JSON.parse(lib.rgblib_list_transfers(this.wallet, assetId));
}

listUnspents(online, settledOnly, skipSync) {
const params = {
online,
settledOnly,
skipSync,
};
const expectedTypes = {
online: "object",
settledOnly: "boolean",
skipSync: "boolean",
};
validateTypes(params, expectedTypes);
return JSON.parse(
lib.rgblib_list_unspents(this.wallet, online, settledOnly, skipSync),
);
}

refresh(online, assetId, filter, skipSync) {
const params = {
online,
Expand Down