mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 12:14:21 +01:00
* Add gRPC, REST, and gRPC-Web clients for server access This commit introduces clients for gRPC, REST, and gRPC-Web to access the server. - gRPC client: Includes additional argument opts ...grpc.CallOption in the interface for future extensibility. - REST client: Factory function accepts http.Client as an argument to allow user customization. - gRPC-Web client: Added a Log method for fast debugging in JavaScript. The decision to use different interfaces for each client type is to accommodate specific features and extensibility requirements for each protocol. * remove grpc web * generate rest * use grpc sdk in CLI * temp wasm * ark sdk * renaming * pr review refactor * pr review refactor * walletStore & configStore * ark sdk wasm wrapper * handle event stream with rest * wip on supporting rest * store init * simulate event stream with rest * fix rest sdk wip * Fix returning forfeit txs in round event * wasm first working e2e example * pr review refactor * pr review refactor * pr review refactor * Fixes --------- Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
133 lines
4.4 KiB
HTML
133 lines
4.4 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Ark SDK WASM Example</title>
|
|
<script src="wasm_exec.js"></script>
|
|
<script>
|
|
const go = new Go();
|
|
WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => {
|
|
go.run(result.instance);
|
|
});
|
|
|
|
function logMessage(message) {
|
|
const logArea = document.getElementById("logArea");
|
|
logArea.value += message + "\n";
|
|
logArea.scrollTop = logArea.scrollHeight;
|
|
}
|
|
|
|
async function conn() {
|
|
try {
|
|
await connect();
|
|
logMessage("Connected to ASP");
|
|
await config();
|
|
} catch (err) {
|
|
logMessage("Connect error: " + err.message);
|
|
}
|
|
}
|
|
|
|
async function receiveAddresses() {
|
|
try {
|
|
const addresses = await receive();
|
|
logMessage("Offchain address: " + addresses.offchainAddr);
|
|
logMessage("Onchain address: " + addresses.onchainAddr);
|
|
logMessage("If in regtest faucet onchain address: " + addresses.onchainAddr);
|
|
} catch (err) {
|
|
logMessage("Receive error: " + err.message);
|
|
}
|
|
}
|
|
|
|
async function getBalance() {
|
|
const bal = await balance(false);
|
|
logMessage("Onchain balance: " + bal.onchain_balance)
|
|
logMessage("Offchain balance: " + bal.offchain_balance)
|
|
}
|
|
|
|
|
|
async function send() {
|
|
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");
|
|
return;
|
|
}
|
|
const amount = parseInt(amountStr, 10);
|
|
|
|
const txID = await sendOffChain(false, [{ To: address, Amount: amount }]);
|
|
logMessage("Sent money with tx ID: " + txID);
|
|
} catch (err) {
|
|
logMessage("Send error: " + err.message);
|
|
}
|
|
}
|
|
|
|
async function config() {
|
|
try {
|
|
const aspUrl = await getAspUrl();
|
|
logMessage("ASP URL: " + aspUrl);
|
|
|
|
const aspPubKeyHex = await getAspPubKeyHex();
|
|
logMessage("ASP PubKey Hex: " + aspPubKeyHex);
|
|
|
|
const transportProtocol = await getTransportProtocol();
|
|
logMessage("Transport Protocol: " + transportProtocol);
|
|
|
|
const explorerUrl = await getExplorerUrl();
|
|
logMessage("Explorer URL: " + explorerUrl);
|
|
|
|
const network = await getNetwork();
|
|
logMessage("Network: " + network);
|
|
} 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);
|
|
try {
|
|
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);
|
|
}
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<h1>Ark SDK WASM Example</h1>
|
|
<div>
|
|
<h2>Wallet</h2>
|
|
<div>
|
|
<button onclick="conn()">Connect</button>
|
|
</div>
|
|
<div>
|
|
<button onclick="receiveAddresses()">Receive</button>
|
|
</div>
|
|
<div>
|
|
<button onclick="getBalance()">Balance</button>
|
|
</div>
|
|
<div>
|
|
<button onclick="board()">Onboard</button>
|
|
<input type="text" id="amount" placeholder="Amount">
|
|
</div>
|
|
<div>
|
|
<button onclick="send()">Send</button>
|
|
<input type="text" id="sendAddress" placeholder="Offchain Address">
|
|
<input type="text" id="amountToSend" placeholder="Amount">
|
|
</div>
|
|
<div>
|
|
<button onclick="config()">Config</button>
|
|
</div>
|
|
</div>
|
|
<textarea id="logArea" rows="20" cols="80" readonly></textarea>
|
|
</body>
|
|
</html>
|