mirror of
https://github.com/aljazceru/ark.git
synced 2026-01-25 06:14:19 +01:00
Update client sdk (#207)
* Add bitcoin networks * Refactor client * Refactor explorer * Refactor store * Refactor wallet * Refactor sdk client * Refactor wasm & Update examples * Move common util funcs to internal/utils * Move to constants for service types * Add unit tests * Parallelize tests * Lint * Add job to gh action * go mod tidy * Fixes * Fixes * Fix compose file * Fixes * Fixes after review: * Drop factory pattern * Drop password from ark client methods * Make singlekey wallet manage store and wallet store instead of defining WalletStore as extension of Store * Move constants to arksdk module * Drop config and expect directory store and wallet as ark client factory args * Fix * Add constants for bitcoin/liquid explorer * Fix test * Fix wasm * Rename client.Client to client.ASPClient * Rename store.Store to store.ConfigStore * Rename wallet.Wallet to wallet.WalletService * Renamings * Lint * Fixes * Move everything to internal/utils & move ComputeVtxoTaprootScript to common * Go mod tidy
This commit is contained in:
committed by
GitHub
parent
e45bff3c70
commit
89df461623
@@ -16,13 +16,26 @@
|
||||
logArea.scrollTop = logArea.scrollHeight;
|
||||
}
|
||||
|
||||
async function conn() {
|
||||
async function initWallet() {
|
||||
try {
|
||||
await connect();
|
||||
logMessage("Connected to ASP");
|
||||
const walletType = "singlekey"
|
||||
const clientType = "rest"
|
||||
const privateKey = document.getElementById("prvkey").value;
|
||||
const password = document.getElementById("i_password").value;
|
||||
if (!password) {
|
||||
logMessage("Init error: password is required");
|
||||
return;
|
||||
}
|
||||
const aspUrl = document.getElementById("aspUrl").value;
|
||||
if (!aspUrl) {
|
||||
logMessage("Init error: asp url is required");
|
||||
return;
|
||||
}
|
||||
await init(walletType, clientType, aspUrl, privateKey, password);
|
||||
logMessage("wallet initialized and connected to ASP");
|
||||
await config();
|
||||
} catch (err) {
|
||||
logMessage("Connect error: " + err.message);
|
||||
logMessage("Init error: " + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,13 +58,18 @@
|
||||
|
||||
|
||||
async function send() {
|
||||
const password = document.getElementById("s_password").value;
|
||||
if (!password) {
|
||||
logMessage("Send error: password is required");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const address = document.getElementById("sendAddress").value;
|
||||
if (!address) {
|
||||
logMessage("Send error: Address is required");
|
||||
return;
|
||||
}
|
||||
|
||||
const amountStr = document.getElementById("amountToSend").value;
|
||||
if (!amountStr) {
|
||||
logMessage("Send error: Amount is required");
|
||||
@@ -59,10 +77,13 @@
|
||||
}
|
||||
const amount = parseInt(amountStr, 10);
|
||||
|
||||
await unlock(password);
|
||||
const txID = await sendOffChain(false, [{ To: address, Amount: amount }]);
|
||||
logMessage("Sent money with tx ID: " + txID);
|
||||
} catch (err) {
|
||||
logMessage("Send error: " + err.message);
|
||||
} finally {
|
||||
await lock(password);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,32 +93,48 @@
|
||||
logMessage("ASP URL: " + aspUrl);
|
||||
|
||||
const aspPubKeyHex = await getAspPubKeyHex();
|
||||
logMessage("ASP PubKey Hex: " + aspPubKeyHex);
|
||||
logMessage("ASP PubKey: " + aspPubKeyHex);
|
||||
|
||||
const transportProtocol = await getTransportProtocol();
|
||||
logMessage("Transport Protocol: " + transportProtocol);
|
||||
const walletType = await getWalletType();
|
||||
logMessage("Wallet Type: " + walletType);
|
||||
|
||||
const explorerUrl = await getExplorerUrl();
|
||||
logMessage("Explorer URL: " + explorerUrl);
|
||||
const clientType = await getClientType();
|
||||
logMessage("Client Type: " + clientType);
|
||||
|
||||
const network = await getNetwork();
|
||||
logMessage("Network: " + network);
|
||||
const roundLifetime = await getRoundLifetime();
|
||||
logMessage("Round Lifetime: " + roundLifetime);
|
||||
|
||||
const unilateralExitDelay = await getUnilateralExitDelay();
|
||||
logMessage("Unilateral Exit Delay: " + unilateralExitDelay);
|
||||
|
||||
const minRelayFee = await getMinRelayFee();
|
||||
logMessage("Min Relay Fee: " + minRelayFee);
|
||||
} catch (err) {
|
||||
logMessage("Config error: " + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function board() {
|
||||
logMessage("Board button clicked");
|
||||
const amountStr = document.getElementById("amount").value;
|
||||
const amount = parseInt(amountStr, 10);
|
||||
logMessage("Amount provided: " + amount);
|
||||
const password = document.getElementById("o_password").value;
|
||||
if (!password) {
|
||||
logMessage("Onboard error: password is required");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log("unlocking...");
|
||||
await unlock(password);
|
||||
console.log(amount, password);
|
||||
const txID = await onboard(amount);
|
||||
logMessage("Onboarded with amount: " + amount + " and txID: " + txID + ", if in regtest mine a block");
|
||||
} catch (err) {
|
||||
logMessage("Board error: " + err.message);
|
||||
logMessage("Onboard error: " + err.message);
|
||||
} finally {
|
||||
await lock(password);
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
@@ -106,7 +143,10 @@
|
||||
<div>
|
||||
<h2>Wallet</h2>
|
||||
<div>
|
||||
<button onclick="conn()">Connect</button>
|
||||
<button onclick="initWallet()">Init</button>
|
||||
<input type="text" id="aspUrl" placeholder="http://localhost:8080">
|
||||
<input type="password" id="i_password" placeholder="password">
|
||||
<input type="text" id="prvkey" placeholder="Optional: privkey (hex)">
|
||||
</div>
|
||||
<div>
|
||||
<button onclick="receiveAddresses()">Receive</button>
|
||||
@@ -117,11 +157,13 @@
|
||||
<div>
|
||||
<button onclick="board()">Onboard</button>
|
||||
<input type="text" id="amount" placeholder="Amount">
|
||||
<input type="password" id="o_password" placeholder="password">
|
||||
</div>
|
||||
<div>
|
||||
<button onclick="send()">Send</button>
|
||||
<input type="text" id="sendAddress" placeholder="Offchain Address">
|
||||
<input type="text" id="amountToSend" placeholder="Amount">
|
||||
<input type="password" id="s_password" placeholder="password">
|
||||
</div>
|
||||
<div>
|
||||
<button onclick="config()">Config</button>
|
||||
|
||||
Reference in New Issue
Block a user