mirror of
https://github.com/aljazceru/ark.git
synced 2026-01-05 04:54: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
@@ -48,11 +48,11 @@ require (
|
||||
go.opentelemetry.io/otel v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.24.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.24.0 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/crypto v0.25.0 // indirect
|
||||
golang.org/x/net v0.27.0 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/text v0.15.0 // indirect
|
||||
golang.org/x/sys v0.22.0 // indirect
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
|
||||
google.golang.org/grpc v1.65.0 // indirect
|
||||
|
||||
@@ -147,15 +147,15 @@ go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
|
||||
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
@@ -169,13 +169,13 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -5,15 +5,30 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
inmemorystore "github.com/ark-network/ark-sdk/store/inmemory"
|
||||
arksdkwasm "github.com/ark-network/ark-sdk/wasm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
aspUrl = "http://localhost:8080"
|
||||
ctx = context.Background()
|
||||
ctx = context.Background()
|
||||
)
|
||||
|
||||
arksdkwasm.New(ctx, aspUrl)
|
||||
store, _ := arksdkwasm.NewLocalStorageStore()
|
||||
if store != nil {
|
||||
if err := arksdkwasm.New(ctx, store); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
} else {
|
||||
storeSvc, err := inmemorystore.NewConfigStore()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
if err := arksdkwasm.New(ctx, storeSvc); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user