Files
ark/pkg/client-sdk/example/covenant/wasm/index.html
Dusan Sekulic b1c9261f14 [SDK] Persist tx history, vtxos & Provide transaction feed (#354)
* SDK - GetTransactionsStream add to rest/grpc

no session, pattern or user messages provided

* SDK - AppDataRepository added, store refactor

This patch introduces a significant refactor of the Ark SDK codebase. The primary changes involve:

1. **Domain Package Introduction**: A new `domain` package has been created under `store`, encapsulating core data structures and interfaces such as `ConfigData`, `Transaction`, `SdkRepository`, and various repository interfaces. This enhances modularity and separation of concerns.

2. **Replacement of Store with Domain Objects**: All references to the `store` package's `StoreData` have been replaced with `domain.ConfigData`. This change reflects a shift towards using domain-driven design, where the core business logic is represented by domain objects.

3. **Repository Pattern Implementation**: The code has been refactored to use repositories for accessing and managing data. `ConfigRepository` and `TransactionRepository` interfaces are introduced, providing methods for managing configuration data and transactions, respectively.

4. **New Storage Implementations**: New storage implementations using BadgerDB are introduced for persisting transactions (`transaction_repository.go`). This change indicates a move towards more robust and scalable data storage solutions.

5. **Service Layer Introduction**: A service layer (`service.go`) is introduced, which acts as a facade for the underlying data repositories. This layer abstracts the data access logic and provides a unified interface for interacting with configuration and transaction data.

6. **Code Simplification and Cleanup**: The patch removes redundant code and simplifies the existing codebase by consolidating store-related logic and enhancing the overall structure of the code.

7. **Testing Enhancements**: Test cases are updated to reflect the changes in the data access layer, ensuring that the new repository pattern and domain objects are properly tested.

Overall, this refactor aims to improve the maintainability, scalability, and testability of the codebase by adopting best practices such as domain-driven design, repository pattern, and separation of concerns.

* 'SDK listen for tx stream

This diff represents a substantial refactor and enhancement of the `ark-sdk` client, which involves modifications to multiple files, primarily in the `pkg/client-sdk` and `server/internal/core/application` directories. Here's a summary of the key changes:

1. **Configuration and Initialization**:
   - Refactor to replace file-based configuration store with a domain-based approach.
   - Introduced `ListenTransactionStream` configuration to allow real-time transaction event listening.

2. **Client SDK Enhancements**:
   - The client SDK now supports asynchronous transaction streaming and handling.
   - Introduced methods to get transaction event channels and stop the client gracefully.
   - Expanded the `ArkClient` interface to include these new functionalities.

3. **Transaction Handling**:
   - Added support for listening to and processing transaction events in real-time.
   - Implemented methods to handle different types of transactions, including boarding, redeem, and round transactions.
   - Expanded the `Transaction` struct to include more metadata, such as `BoardingVOut`.

4. **Repository Changes**:
   - Introduced `VtxoRepository` for managing VTXO-related operations.
   - Modified `AppDataRepository` to include `VtxoRepository`.

5. **Example and Test Adjustments**:
   - Updated example code to utilize the new transaction streaming capabilities.
   - Adjusted tests to reflect changes in client initialization and configuration handling.

6. **Dependency Updates**:
   - Updated `go.mod` and `go.sum` to include new dependencies such as `badger` for data storage and potentially updated versions of existing packages.

These changes collectively enhance the functionality of the `ark-sdk` client by enabling real-time transaction handling, improving configuration management, and providing a more robust and scalable client architecture. This update seems to be aimed at improving the efficiency and responsiveness of the client application, likely in response to increased demands for real-time data processing and analysis.'

* merge

* go work sync

* test fix

* Tiny refactor (#2)

* tiny refactor

* renaming

* Renamings

* Fixes (#3)

---------

Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
2024-10-17 17:36:48 +02:00

176 lines
6.3 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("ark-sdk.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 initWallet() {
try {
const chain = "liquid";
const walletType = "singlekey";
const clientType = "rest";
const privateKey = document.getElementById("prvkey").value;
const password = document.getElementById("i_password").value;
const explorerUrl = "";
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, chain, explorerUrl);
logMessage("wallet initialized and connected to ASP");
await config();
} catch (err) {
logMessage("Init 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() {
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");
return;
}
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);
}
}
async function config() {
try {
const aspUrl = await getAspUrl();
logMessage("ASP URL: " + aspUrl);
const aspPubKeyHex = await getAspPubKeyHex();
logMessage("ASP PubKey: " + aspPubKeyHex);
const walletType = await getWalletType();
logMessage("Wallet Type: " + walletType);
const clientType = await getClientType();
logMessage("Client Type: " + clientType);
const roundLifetime = await getRoundLifetime();
logMessage("Round Lifetime: " + roundLifetime);
const unilateralExitDelay = await getUnilateralExitDelay();
logMessage("Unilateral Exit Delay: " + unilateralExitDelay);
} catch (err) {
logMessage("Config error: " + err.message);
}
}
async function board() {
const amountStr = document.getElementById("amount").value;
const amount = parseInt(amountStr, 10);
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);
console.log("onboarding...");
const txID = await onboard(amount);
logMessage("Onboarded with amount: " + amount + " and txID: " + txID + ", if in regtest mine a block");
} catch (err) {
logMessage("Onboard error: " + err.message);
} finally {
await lock(password);
}
}
</script>
</head>
<body>
<h1>Ark SDK WASM Example</h1>
<div>
<h2>Wallet</h2>
<div>
<button onclick="initWallet()">Init</button>
<input type="text" id="aspUrl" placeholder="http://localhost:6060">
<input type="password" id="i_password" placeholder="password">
<input type="text" id="prvkey" placeholder="Optional: privkey (hex)">
</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">
<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>
</div>
</div>
<textarea id="logArea" rows="20" cols="80" readonly></textarea>
</body>
</html>