Add first version of client SDK (#193)

* 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>
This commit is contained in:
Dusan Sekulic
2024-07-18 16:27:14 +02:00
committed by GitHub
parent 498394a191
commit 1f42843a69
110 changed files with 11738 additions and 86 deletions

5
.gitignore vendored
View File

@@ -1,2 +1,5 @@
.DS_Store
.vscode/
.vscode/
main.wasm
wasm_exec.js

View File

@@ -74,7 +74,7 @@ Inside the `arkd` container is shipped the `ark` CLI. You can submit payment to
```bash
alias ark='docker exec -it arkd ark'
ark init --password <password> --ark-url localhost:6000
ark init --password <password> --ark-url localhost:8080
```
This will add a `state.json` file to the following directory:
@@ -88,7 +88,7 @@ This will add a `state.json` file to the following directory:
```bash
export ARK_WALLET_DATADIR=path/to/custom
ark init --password <password> --ark-url localhost:6000 --network testnet
ark init --password <password> --ark-url localhost:8080 --network testnet
```
Add funds to the ark wallet:
@@ -116,7 +116,7 @@ In **another tab**, setup another ark wallet with:
```bash
export ARK_WALLET_DATADIR=./datadir
alias ark2=$(pwd)/build/ark-<os>-<arch>
ark2 init --password <password> --ark-url localhost:6000 --network testnet
ark2 init --password <password> --ark-url localhost:8080 --network testnet
```
**Note:** `ark2` should always run in the second tab.
@@ -130,7 +130,7 @@ ark2 receive
{
"offchain_address": <address starting with "tark1q...">,
"onchain_address": <address starting with "tex1q...">,
"relays": ["localhost:6000"]
"relays": ["localhost:8080"]
}
```

View File

@@ -2,14 +2,11 @@ package main
import (
"fmt"
"strings"
"time"
arkgrpcclient "github.com/ark-network/ark-sdk/grpc"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
"github.com/urfave/cli/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)
type vtxo struct {
@@ -89,29 +86,6 @@ func getClientFromState(ctx *cli.Context) (arkv1.ArkServiceClient, func(), error
}
func getClient(addr string) (arkv1.ArkServiceClient, func(), error) {
creds := insecure.NewCredentials()
port := 80
if strings.HasPrefix(addr, "https://") {
addr = strings.TrimPrefix(addr, "https://")
creds = credentials.NewTLS(nil)
port = 443
}
if !strings.Contains(addr, ":") {
addr = fmt.Sprintf("%s:%d", addr, port)
}
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(creds))
if err != nil {
return nil, nil, err
}
client := arkv1.NewArkServiceClient(conn)
closeFn := func() {
err := conn.Close()
if err != nil {
fmt.Printf("error closing connection: %s\n", err)
}
}
return client, closeFn, nil
client, cleanFn, err := arkgrpcclient.New(addr)
return client.Service(), cleanFn, err
}

View File

@@ -1,19 +1,22 @@
module github.com/ark-network/ark-cli
go 1.21.0
go 1.22.2
replace github.com/ark-network/ark/common => ../common
replace github.com/ark-network/ark => ../server
replace github.com/ark-network/ark-sdk => ../pkg/client-sdk
require (
github.com/ark-network/ark v0.0.0-00010101000000-000000000000
github.com/ark-network/ark-sdk v0.0.0-00010101000000-000000000000
github.com/ark-network/ark/common v0.0.0
github.com/btcsuite/btcd v0.24.0
github.com/btcsuite/btcd/btcec/v2 v2.3.3
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/urfave/cli/v2 v2.26.0
github.com/urfave/cli/v2 v2.27.2
golang.org/x/crypto v0.23.0
golang.org/x/term v0.20.0
)
@@ -27,16 +30,16 @@ require (
require (
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/vulpemventures/go-elements v0.5.3
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.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.64.0
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
)

View File

@@ -2,12 +2,12 @@ github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBA
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
github.com/btcsuite/btcd v0.24.0 h1:gL3uHE/IaFj6fcZSu03SvqPMSx7s/dPzfpG/atRwWdo=
github.com/btcsuite/btcd v0.24.0/go.mod h1:K4IDc1593s8jKXIF7yS7yCTSxrknB9z0STzc2j6XgE4=
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcec/v2 v2.3.3 h1:6+iXlDKE8RMtKsvK0gshlXIuPbyWM/h84Ensb7o3sC0=
github.com/btcsuite/btcd/btcec/v2 v2.3.3/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8=
@@ -28,8 +28,8 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -84,16 +84,16 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/urfave/cli/v2 v2.26.0 h1:3f3AMg3HpThFNT4I++TKOejZO8yU55t3JnnSr4S4QEI=
github.com/urfave/cli/v2 v2.26.0/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 h1:CTcw80hz/Sw8hqlKX5ZYvBUF5gAHSHwdjXxRf/cjDcI=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941/go.mod h1:GXBJykxW2kUcktGdsgyay7uwwWvkljASfljNcT0mbh8=
github.com/vulpemventures/go-elements v0.5.3 h1:zaC/ynHFwCAzFSOMfzb6BcbD6FXASppSiGMycc95WVA=
github.com/vulpemventures/go-elements v0.5.3/go.mod h1:aBGuWXHaiAIUIcwqCdtEh2iQ3kJjKwHU9ywvhlcRSeU=
github.com/vulpemventures/go-secp256k1-zkp v1.1.6 h1:BmsrmXRLUibwa75Qkk8yELjpzCzlAjYFGLiLiOdq7Xo=
github.com/vulpemventures/go-secp256k1-zkp v1.1.6/go.mod h1:zo7CpgkuPgoe7fAV+inyxsI9IhGmcoFgyD8nqZaPSOM=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
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=
@@ -132,8 +132,8 @@ google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY=
google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=

View File

@@ -1,2 +1,2 @@
test:
test:
go test -v ./...

View File

@@ -3,13 +3,13 @@ module github.com/ark-network/ark/common
go 1.21.0
require (
github.com/btcsuite/btcd v0.23.1
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/btcsuite/btcd/btcutil v1.1.3
github.com/btcsuite/btcd/btcutil/psbt v1.1.4
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0
github.com/stretchr/testify v1.8.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/btcutil v1.1.5
github.com/btcsuite/btcd/btcutil/psbt v1.1.9
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/stretchr/testify v1.9.0
)
require (

View File

@@ -1,22 +1,23 @@
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/btcsuite/btcd v0.23.1 h1:IB8cVQcC2X5mHbnfirLG5IZnkWYNTPlLZVrxUYSotbE=
github.com/btcsuite/btcd v0.23.1/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY=
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ=
github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0=
github.com/btcsuite/btcd/btcutil/psbt v1.1.4 h1:Edx4AfBn+YPam2KP5AobDitulGp4r1Oibm8oruzkMdI=
github.com/btcsuite/btcd/btcutil/psbt v1.1.4/go.mod h1:9AyU6EQVJ9Iw9zPyNT1lcdHd6cnEZdno5wLu5FY74os=
github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8=
github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00=
github.com/btcsuite/btcd/btcutil/psbt v1.1.9 h1:UmfOIiWMZcVMOLaN+lxbbLSuoINGS1WmK1TZNI0b4yk=
github.com/btcsuite/btcd/btcutil/psbt v1.1.9/go.mod h1:ehBEvU91lxSlXtA+zZz3iFYx7Yq9eqnKx4/kSrnsvMY=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
@@ -35,8 +36,8 @@ github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@@ -51,6 +52,7 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@@ -68,11 +70,9 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 h1:CTcw80hz/Sw8hqlKX5ZYvBUF5gAHSHwdjXxRf/cjDcI=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941/go.mod h1:GXBJykxW2kUcktGdsgyay7uwwWvkljASfljNcT0mbh8=

View File

@@ -32,7 +32,7 @@ services:
- ARK_ROUND_LIFETIME=512
- ARK_DB_TYPE=sqlite
ports:
- "6000:6000"
- "8080:6000"
volumes:
oceand:

View File

@@ -31,7 +31,7 @@ services:
- ARK_ROUND_INTERVAL=10
- ARK_NETWORK=testnet
ports:
- "6000:6000"
- "8080:6000"
volumes:
- arkd:/app/data
- ark:/app/wallet-data

6
pkg/client-sdk/Makefile Normal file
View File

@@ -0,0 +1,6 @@
genrest:
swagger generate client -f ./../../server/api-spec/openapi/swagger/ark/v1/admin.swagger.json -t ./rest/admin --client-package=arkadminrestclient
swagger generate client -f ./../../server/api-spec/openapi/swagger/ark/v1/service.swagger.json -t ./rest/service --client-package=arkservicerestclient
vet:
go vet ./...

1153
pkg/client-sdk/ark_sdk.go Normal file

File diff suppressed because it is too large Load Diff

296
pkg/client-sdk/common.go Normal file
View File

@@ -0,0 +1,296 @@
package arksdk
import (
"fmt"
"io"
"net/http"
"sort"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
"github.com/ark-network/ark/common"
"github.com/ark-network/ark/common/tree"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/vulpemventures/go-elements/address"
"github.com/vulpemventures/go-elements/network"
"github.com/vulpemventures/go-elements/payment"
"github.com/vulpemventures/go-elements/psetv2"
"github.com/vulpemventures/go-elements/taproot"
)
func getAddress(
walletPubKey []byte,
aspPubKey []byte,
unilateralExitDelay int64,
net string,
) (offchainAddr, onchainAddr, redemptionAddr string, err error) {
userPubkey, err := secp256k1.ParsePubKey(walletPubKey)
if err != nil {
return
}
aspPubkey, err := secp256k1.ParsePubKey(aspPubKey)
if err != nil {
return
}
arkNet, liquidNet := networkFromString(net)
arkAddr, err := common.EncodeAddress(arkNet.Addr, userPubkey, aspPubkey)
if err != nil {
return
}
p2wpkh := payment.FromPublicKey(userPubkey, liquidNet, nil)
liquidAddr, err := p2wpkh.WitnessPubKeyHash()
if err != nil {
return
}
vtxoTapKey, _, err := computeVtxoTaprootScript(
userPubkey, aspPubkey, uint(unilateralExitDelay),
)
if err != nil {
return
}
_, n := networkFromString(net)
pay, err := payment.FromTweakedKey(vtxoTapKey, n, nil)
if err != nil {
return
}
redemptionAddr, err = pay.TaprootAddress()
if err != nil {
return
}
offchainAddr = arkAddr
onchainAddr = liquidAddr
return
}
func computeVtxoTaprootScript(
userPubkey, aspPubkey *secp256k1.PublicKey, exitDelay uint,
) (*secp256k1.PublicKey, *taproot.TapscriptElementsProof, error) {
redeemClosure := &tree.CSVSigClosure{
Pubkey: userPubkey,
Seconds: exitDelay,
}
forfeitClosure := &tree.ForfeitClosure{
Pubkey: userPubkey,
AspPubkey: aspPubkey,
}
redeemLeaf, err := redeemClosure.Leaf()
if err != nil {
return nil, nil, err
}
forfeitLeaf, err := forfeitClosure.Leaf()
if err != nil {
return nil, nil, err
}
vtxoTaprootTree := taproot.AssembleTaprootScriptTree(
*redeemLeaf, *forfeitLeaf,
)
root := vtxoTaprootTree.RootNode.TapHash()
unspendableKey := tree.UnspendableKey()
vtxoTaprootKey := taproot.ComputeTaprootOutputKey(unspendableKey, root[:])
redeemLeafHash := redeemLeaf.TapHash()
proofIndex := vtxoTaprootTree.LeafProofIndex[redeemLeafHash]
proof := vtxoTaprootTree.LeafMerkleProofs[proofIndex]
return vtxoTaprootKey, &proof, nil
}
func toCongestionTree(treeFromProto *arkv1.Tree) (tree.CongestionTree, error) {
levels := make(tree.CongestionTree, 0, len(treeFromProto.Levels))
for _, level := range treeFromProto.Levels {
nodes := make([]tree.Node, 0, len(level.Nodes))
for _, node := range level.Nodes {
nodes = append(nodes, tree.Node{
Txid: node.Txid,
Tx: node.Tx,
ParentTxid: node.ParentTxid,
Leaf: false,
})
}
levels = append(levels, nodes)
}
for j, treeLvl := range levels {
for i, node := range treeLvl {
if len(levels.Children(node.Txid)) == 0 {
levels[j][i].Leaf = true
}
}
}
return levels, nil
}
func networkFromString(net string) (*common.Network, *network.Network) {
if net == "testnet" {
return &common.TestNet, &network.Testnet
}
if net == "regtest" {
return &common.RegTest, &network.Regtest
}
return &common.Liquid, &network.Liquid
}
func testEsploraEndpoint(net *network.Network, url string) error {
resp, err := http.Get(fmt.Sprintf("%s/asset/%s", url, net.AssetID))
if err != nil {
return err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
if resp.StatusCode != http.StatusOK {
return fmt.Errorf(string(body))
}
return nil
}
func castCongestionTree(congestionTree tree.CongestionTree) *arkv1.Tree {
levels := make([]*arkv1.TreeLevel, 0, len(congestionTree))
for _, level := range congestionTree {
levelProto := &arkv1.TreeLevel{
Nodes: make([]*arkv1.Node, 0, len(level)),
}
for _, node := range level {
levelProto.Nodes = append(levelProto.Nodes, &arkv1.Node{
Txid: node.Txid,
Tx: node.Tx,
ParentTxid: node.ParentTxid,
})
}
levels = append(levels, levelProto)
}
return &arkv1.Tree{
Levels: levels,
}
}
func coinSelect(vtxos []vtxo, amount uint64, sortByExpirationTime bool) ([]vtxo, uint64, error) {
selected := make([]vtxo, 0)
notSelected := make([]vtxo, 0)
selectedAmount := uint64(0)
if sortByExpirationTime {
// sort vtxos by expiration (older first)
sort.SliceStable(vtxos, func(i, j int) bool {
if vtxos[i].expireAt == nil || vtxos[j].expireAt == nil {
return false
}
return vtxos[i].expireAt.Before(*vtxos[j].expireAt)
})
}
for _, vtxo := range vtxos {
if selectedAmount >= amount {
notSelected = append(notSelected, vtxo)
break
}
selected = append(selected, vtxo)
selectedAmount += vtxo.amount
}
if selectedAmount < amount {
return nil, 0, fmt.Errorf("not enough funds to cover amount%d", amount)
}
change := selectedAmount - amount
if change < DUST {
if len(notSelected) > 0 {
selected = append(selected, notSelected[0])
change += notSelected[0].amount
}
}
return selected, change, nil
}
func findSweepClosure(
congestionTree tree.CongestionTree,
) (*taproot.TapElementsLeaf, uint, error) {
root, err := congestionTree.Root()
if err != nil {
return nil, 0, err
}
// find the sweep closure
tx, err := psetv2.NewPsetFromBase64(root.Tx)
if err != nil {
return nil, 0, err
}
var seconds uint
var sweepClosure *taproot.TapElementsLeaf
for _, tapLeaf := range tx.Inputs[0].TapLeafScript {
closure := &tree.CSVSigClosure{}
valid, err := closure.Decode(tapLeaf.Script)
if err != nil {
continue
}
if valid && closure.Seconds > seconds {
seconds = closure.Seconds
sweepClosure = &tapLeaf.TapElementsLeaf
}
}
if sweepClosure == nil {
return nil, 0, fmt.Errorf("sweep closure not found")
}
return sweepClosure, seconds, nil
}
func decodeReceiverAddress(addr string) (
bool, []byte, *secp256k1.PublicKey, error,
) {
outputScript, err := address.ToOutputScript(addr)
if err != nil {
_, userPubkey, _, err := common.DecodeAddress(addr)
if err != nil {
return false, nil, nil, err
}
return false, nil, userPubkey, nil
}
return true, outputScript, nil, nil
}
func isOnchainOnly(receivers []*arkv1.Output) bool {
for _, receiver := range receivers {
isOnChain, _, _, err := decodeReceiverAddress(receiver.Address)
if err != nil {
continue
}
if !isOnChain {
return false
}
}
return true
}

View File

@@ -0,0 +1,287 @@
package arksdk
import (
"bytes"
"context"
"fmt"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
"github.com/ark-network/ark/common"
"github.com/ark-network/ark/common/tree"
"github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
log "github.com/sirupsen/logrus"
"github.com/vulpemventures/go-elements/psetv2"
)
func (a *arkClient) handleRoundStream(
ctx context.Context,
paymentID string,
vtxosToSign []vtxo,
receivers []*arkv1.Output,
) (string, error) {
eventStream, err := a.innerClient.getEventStream(ctx, paymentID, &arkv1.GetEventStreamRequest{})
if err != nil {
return "", err
}
var pingStop func()
pingReq := &arkv1.PingRequest{
PaymentId: paymentID,
}
for pingStop == nil {
pingStop = a.ping(ctx, pingReq)
}
defer pingStop()
for {
select {
case <-ctx.Done():
return "", ctx.Err()
case event := <-eventStream.eventResp:
if e := event.GetRoundFailed(); e != nil {
pingStop()
return "", fmt.Errorf("round failed: %s", e.GetReason())
}
if e := event.GetRoundFinalization(); e != nil {
pingStop()
log.Info("a round finalization started")
signedForfeitTxs, err := a.handleRoundFinalization(
e, vtxosToSign, receivers,
)
if err != nil {
return "", err
}
if len(signedForfeitTxs) <= 0 {
log.Info("no forfeit txs to sign, waiting for the next round")
continue
}
log.Info("finalizing payment... ")
_, err = a.innerClient.finalizePayment(ctx, &arkv1.FinalizePaymentRequest{
SignedForfeitTxs: signedForfeitTxs,
})
if err != nil {
return "", err
}
log.Info("done.")
log.Info("waiting for round finalization...")
}
if event.GetRoundFinalized() != nil {
return event.GetRoundFinalized().GetPoolTxid(), nil
}
case e := <-eventStream.err:
return "", e
}
}
}
func (a *arkClient) handleRoundFinalization(
finalization *arkv1.RoundFinalizationEvent,
vtxosToSign []vtxo,
receivers []*arkv1.Output,
) ([]string, error) {
if err := a.validateCongestionTree(finalization, receivers); err != nil {
return nil, fmt.Errorf("failed to verify congestion tree: %s", err)
}
return a.loopAndSign(
finalization.GetForfeitTxs(), vtxosToSign, finalization.GetConnectors(),
)
}
func (a *arkClient) validateCongestionTree(
finalization *arkv1.RoundFinalizationEvent,
receivers []*arkv1.Output,
) error {
poolTx := finalization.GetPoolTx()
ptx, err := psetv2.NewPsetFromBase64(poolTx)
if err != nil {
return err
}
congestionTree, err := toCongestionTree(finalization.GetCongestionTree())
if err != nil {
return err
}
connectors := finalization.GetConnectors()
aspPubkey, err := secp256k1.ParsePubKey(a.aspPubKey)
if err != nil {
return err
}
if !isOnchainOnly(receivers) {
if err := tree.ValidateCongestionTree(
congestionTree, poolTx, aspPubkey, int64(a.roundLifeTime),
); err != nil {
return err
}
}
if err := common.ValidateConnectors(poolTx, connectors); err != nil {
return err
}
if err := a.validateReceivers(ptx, receivers, &congestionTree, aspPubkey); err != nil {
return err
}
log.Infoln("congestion tree validated")
return nil
}
func (a *arkClient) validateReceivers(
ptx *psetv2.Pset,
receivers []*arkv1.Output,
congestionTree *tree.CongestionTree,
aspPubkey *secp256k1.PublicKey,
) error {
for _, receiver := range receivers {
isOnChain, onchainScript, userPubkey, err := decodeReceiverAddress(receiver.Address)
if err != nil {
return err
}
if isOnChain {
if err := a.validateOnChainReceiver(ptx, receiver, onchainScript); err != nil {
return err
}
} else {
if err := a.validateOffChainReceiver(congestionTree, receiver, userPubkey, aspPubkey); err != nil {
return err
}
}
}
return nil
}
func (a *arkClient) validateOnChainReceiver(
ptx *psetv2.Pset,
receiver *arkv1.Output,
onchainScript []byte,
) error {
found := false
for _, output := range ptx.Outputs {
if bytes.Equal(output.Script, onchainScript) {
if output.Value != receiver.Amount {
return fmt.Errorf(
"invalid collaborative exit output amount: got %d, want %d",
output.Value, receiver.Amount,
)
}
found = true
break
}
}
if !found {
return fmt.Errorf("collaborative exit output not found: %s", receiver.Address)
}
return nil
}
func (a *arkClient) validateOffChainReceiver(
congestionTree *tree.CongestionTree,
receiver *arkv1.Output,
userPubkey, aspPubkey *secp256k1.PublicKey,
) error {
found := false
outputTapKey, _, err := computeVtxoTaprootScript(
userPubkey, aspPubkey, uint(a.unilateralExitDelay),
)
if err != nil {
return err
}
leaves := congestionTree.Leaves()
for _, leaf := range leaves {
tx, err := psetv2.NewPsetFromBase64(leaf.Tx)
if err != nil {
return err
}
for _, output := range tx.Outputs {
if len(output.Script) == 0 {
continue
}
if bytes.Equal(output.Script[2:], schnorr.SerializePubKey(outputTapKey)) {
if output.Value == receiver.Amount {
found = true
break
}
}
}
if found {
break
}
}
if !found {
return fmt.Errorf("off-chain send output not found: %s", receiver.Address)
}
return nil
}
func (a *arkClient) loopAndSign(
forfeitTxs []string, vtxosToSign []vtxo, connectors []string,
) ([]string, error) {
signedForfeits := make([]string, 0)
connectorsTxids := make([]string, 0, len(connectors))
for _, connector := range connectors {
p, _ := psetv2.NewPsetFromBase64(connector)
utx, _ := p.UnsignedTx()
txid := utx.TxHash().String()
connectorsTxids = append(connectorsTxids, txid)
}
for _, forfeitTx := range forfeitTxs {
pset, err := psetv2.NewPsetFromBase64(forfeitTx)
if err != nil {
return nil, err
}
for _, input := range pset.Inputs {
inputTxid := chainhash.Hash(input.PreviousTxid).String()
for _, coin := range vtxosToSign {
if inputTxid == coin.txid {
signedPset, err := a.signForfeitTx(forfeitTx, pset, connectorsTxids)
if err != nil {
return nil, err
}
signedForfeits = append(signedForfeits, signedPset)
}
}
}
}
return signedForfeits, nil
}
func (a *arkClient) signForfeitTx(
txStr string, tx *psetv2.Pset, connectorsTxids []string,
) (string, error) {
connectorTxid := chainhash.Hash(tx.Inputs[0].PreviousTxid).String()
connectorFound := false
for _, id := range connectorsTxids {
if id == connectorTxid {
connectorFound = true
break
}
}
if !connectorFound {
return "", fmt.Errorf("connector txid %s not found in the connectors list", connectorTxid)
}
return a.wallet.SignTransaction(a.explorerSvc, txStr)
}

View File

@@ -0,0 +1,243 @@
package main
import (
"context"
"fmt"
"io"
"os/exec"
"strings"
"sync"
"time"
arksdk "github.com/ark-network/ark-sdk"
inmemorystore "github.com/ark-network/ark-sdk/store/inmemory"
log "github.com/sirupsen/logrus"
)
func main() {
var (
//grpcAspUrl = "localhost:8080"
restAspUrl = "http://localhost:8080"
//grpcProtocol = arksdk.Grpc
restProtocol = arksdk.Rest
ctx = context.Background()
aspUrl = restAspUrl
protocol = restProtocol
)
log.Info("alice is setting up her ark wallet...")
aliceConfigStore, err := inmemorystore.New(aspUrl, protocol)
if err != nil {
log.Fatal(err)
}
aliceWalletStore := inmemorystore.NewWalletStore()
aliceWallet, err := arksdk.NewSingleKeyWallet(ctx, aliceWalletStore)
if err != nil {
log.Fatal(err)
}
aliceArkClient, err := arksdk.New(
ctx,
aliceWallet,
aliceConfigStore,
)
if err != nil {
log.Fatal(err)
}
if err := aliceArkClient.Connect(ctx); err != nil {
log.Fatal(err)
}
log.Info("alice is acquiring onchain funds...")
_, aliceOnchainAddr, err := aliceArkClient.Receive(ctx)
if err != nil {
log.Fatal(err)
}
if _, err := runCommand("nigiri", "faucet", "--liquid", aliceOnchainAddr); err != nil {
log.Fatal(err)
}
if err := generateBlock(); err != nil {
log.Fatal(err)
}
onboardAmount := uint64(20000)
log.Infof("alice is onboarding with %d sats offchain...", onboardAmount)
txid, err := aliceArkClient.Onboard(ctx, onboardAmount)
if err != nil {
log.Fatal(err)
}
if err := generateBlock(); err != nil {
log.Fatal(err)
}
time.Sleep(5 * time.Second)
log.Infof("alice onboarded with tx: %s", txid)
aliceBalance, err := aliceArkClient.Balance(ctx, false)
if err != nil {
log.Fatal(err)
}
log.Infof("alice onchain balance: %d", aliceBalance.OnchainBalance.SpendableAmount)
log.Infof("alice offchain balance: %d", aliceBalance.OffchainBalance.Total)
bobConfigStore, err := inmemorystore.New(aspUrl, protocol)
if err != nil {
log.Fatal(err)
}
fmt.Println("")
log.Info("bob is setting up his ark wallet...")
bobWalletStore := inmemorystore.NewWalletStore()
if _, err := bobWalletStore.CreatePrivateKey(); err != nil {
log.Fatal(err)
}
bobWallet, err := arksdk.NewSingleKeyWallet(ctx, bobWalletStore)
if err != nil {
log.Fatal(err)
}
bobArkClient, err := arksdk.New(
ctx, bobWallet, bobConfigStore,
)
if err != nil {
log.Fatal(err)
}
if err := bobArkClient.Connect(ctx); err != nil {
log.Fatal(err)
}
bobOffchainAddr, _, err := bobArkClient.Receive(ctx)
if err != nil {
log.Fatal(err)
}
bobBalance, err := bobArkClient.Balance(ctx, false)
if err != nil {
log.Fatal(err)
}
log.Infof("bob onchain balance: %d", bobBalance.OnchainBalance.SpendableAmount)
log.Infof("bob offchain balance: %d", bobBalance.OffchainBalance.Total)
amount := uint64(1000)
fmt.Println("")
log.Infof("alice is sending %d sats to bob offchain...", amount)
txid, err = aliceArkClient.SendOffChain(
ctx,
false,
[]arksdk.Receiver{
{
To: bobOffchainAddr,
Amount: amount,
},
})
if err != nil {
log.Fatal(err)
}
log.Infof("payment completed in round tx: %s", txid)
if err := generateBlock(); err != nil {
log.Fatal(err)
}
time.Sleep(5 * time.Second)
aliceBalance, err = aliceArkClient.Balance(ctx, false)
if err != nil {
log.Fatal(err)
}
fmt.Println("")
log.Infof("alice onchain balance: %d", aliceBalance.OnchainBalance.SpendableAmount)
log.Infof("alice offchain balance: %d", aliceBalance.OffchainBalance.Total)
bobBalance, err = bobArkClient.Balance(ctx, false)
if err != nil {
log.Fatal(err)
}
log.Infof("bob onchain balance: %d", bobBalance.OnchainBalance.SpendableAmount)
log.Infof("bob offchain balance: %d", bobBalance.OffchainBalance.Total)
}
func runCommand(name string, arg ...string) (string, error) {
errb := new(strings.Builder)
cmd := newCommand(name, arg...)
stdout, err := cmd.StdoutPipe()
if err != nil {
return "", err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return "", err
}
if err := cmd.Start(); err != nil {
return "", err
}
output := new(strings.Builder)
errorb := new(strings.Builder)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
if _, err := io.Copy(output, stdout); err != nil {
fmt.Fprintf(errb, "error reading stdout: %s", err)
}
}()
go func() {
defer wg.Done()
if _, err := io.Copy(errorb, stderr); err != nil {
fmt.Fprintf(errb, "error reading stderr: %s", err)
}
}()
wg.Wait()
if err := cmd.Wait(); err != nil {
if errMsg := errorb.String(); len(errMsg) > 0 {
return "", fmt.Errorf(errMsg)
}
if outMsg := output.String(); len(outMsg) > 0 {
return "", fmt.Errorf(outMsg)
}
return "", err
}
if errMsg := errb.String(); len(errMsg) > 0 {
return "", fmt.Errorf(errMsg)
}
return strings.Trim(output.String(), "\n"), nil
}
func newCommand(name string, arg ...string) *exec.Cmd {
cmd := exec.Command(name, arg...)
return cmd
}
func generateBlock() error {
if _, err := runCommand("nigiri", "rpc", "--liquid", "generatetoaddress", "1", "el1qqwk722tghgkgmh3r2ph4d2apwj0dy9xnzlenzklx8jg3z299fpaw56trre9gpk6wmw0u4qycajqeva3t7lzp7wnacvwxha59r"); err != nil {
return err
}
time.Sleep(6 * time.Second)
return nil
}

View File

@@ -0,0 +1,25 @@
## USAGE
This example demonstrates how to compile ARK Go SDK to WebAssembly and use it in a web page.
1. Create a Go file with the main package, check [main.go](main.go).
2. Copy `wasm_exec.js`:
```bash
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
```
3. Build the Go code to WebAssembly:
```bash
GOOS=js GOARCH=wasm go build -o main.wasm main.go
```
4. Load the WebAssembly module in a web page, check [index.html](index.html).
5. Serve the files:
```bash
python3 -m http.server 8000
```

View File

@@ -0,0 +1,61 @@
module ark/pkg/client-sdk/example
go 1.22.2
replace github.com/ark-network/ark => ./../../../../server
replace github.com/ark-network/ark/common => ./../../../../common
replace github.com/ark-network/ark-sdk => ./../..
require github.com/ark-network/ark-sdk v0.0.0-00010101000000-000000000000
require (
github.com/ark-network/ark v0.0.0-00010101000000-000000000000 // indirect
github.com/ark-network/ark/common v0.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/btcsuite/btcd v0.24.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/btcutil/psbt v1.1.9 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 // indirect
github.com/vulpemventures/go-elements v0.5.3 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
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/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.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
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -0,0 +1,206 @@
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8=
github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00=
github.com/btcsuite/btcd/btcutil/psbt v1.1.9 h1:UmfOIiWMZcVMOLaN+lxbbLSuoINGS1WmK1TZNI0b4yk=
github.com/btcsuite/btcd/btcutil/psbt v1.1.9/go.mod h1:ehBEvU91lxSlXtA+zZz3iFYx7Yq9eqnKx4/kSrnsvMY=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU=
github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo=
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w=
github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
github.com/go-openapi/loads v0.22.0 h1:ECPGd4jX1U6NApCGG1We+uEozOAvXvJSF4nnwHZ8Aco=
github.com/go-openapi/loads v0.22.0/go.mod h1:yLsaTCS92mnSAZX5WWoxszLj0u+Ojl+Zs5Stn1oF+rs=
github.com/go-openapi/runtime v0.28.0 h1:gpPPmWSNGo214l6n8hzdXYhPuJcGtziTOgUpvsFWGIQ=
github.com/go-openapi/runtime v0.28.0/go.mod h1:QN7OzcS+XuYmkQLw05akXk0jRH/eZ3kb18+1KwW9gyc=
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3BumrGD58=
github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 h1:CTcw80hz/Sw8hqlKX5ZYvBUF5gAHSHwdjXxRf/cjDcI=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941/go.mod h1:GXBJykxW2kUcktGdsgyay7uwwWvkljASfljNcT0mbh8=
github.com/vulpemventures/go-elements v0.5.3 h1:zaC/ynHFwCAzFSOMfzb6BcbD6FXASppSiGMycc95WVA=
github.com/vulpemventures/go-elements v0.5.3/go.mod h1:aBGuWXHaiAIUIcwqCdtEh2iQ3kJjKwHU9ywvhlcRSeU=
github.com/vulpemventures/go-secp256k1-zkp v1.1.6 h1:BmsrmXRLUibwa75Qkk8yELjpzCzlAjYFGLiLiOdq7Xo=
github.com/vulpemventures/go-secp256k1-zkp v1.1.6/go.mod h1:zo7CpgkuPgoe7fAV+inyxsI9IhGmcoFgyD8nqZaPSOM=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
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/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/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=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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/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/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=
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw=
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -0,0 +1,132 @@
<!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>

View File

@@ -0,0 +1,19 @@
//go:build js && wasm
// +build js,wasm
package main
import (
"context"
arksdkwasm "github.com/ark-network/ark-sdk/wasm"
)
func main() {
var (
aspUrl = "http://localhost:8080"
ctx = context.Background()
)
arksdkwasm.New(ctx, aspUrl)
}

250
pkg/client-sdk/explorer.go Normal file
View File

@@ -0,0 +1,250 @@
package arksdk
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"time"
"github.com/vulpemventures/go-elements/network"
"github.com/vulpemventures/go-elements/psetv2"
"github.com/vulpemventures/go-elements/transaction"
)
type utxo struct {
Txid string `json:"txid"`
Vout uint32 `json:"vout"`
Amount uint64 `json:"value"`
Asset string `json:"asset"`
Status struct {
Confirmed bool `json:"confirmed"`
Blocktime int64 `json:"block_time"`
} `json:"status"`
}
type Explorer interface {
GetTxHex(txid string) (string, error)
Broadcast(txHex string) (string, error)
GetUtxos(addr string) ([]utxo, error)
GetBalance(addr, asset string) (uint64, error)
GetRedeemedVtxosBalance(
addr string, unilateralExitDelay int64,
) (uint64, map[int64]uint64, error)
GetTxBlockTime(
txid string,
) (confirmed bool, blocktime int64, err error)
GetNetwork() *network.Network
}
type explorer struct {
cache map[string]string
baseUrl string
net string
}
func NewExplorer(baseUrl string, net string) Explorer {
return &explorer{
cache: make(map[string]string),
baseUrl: baseUrl,
net: net,
}
}
func (e *explorer) GetNetwork() *network.Network {
_, liquidNet := networkFromString(e.net)
return liquidNet
}
func (e *explorer) GetTxHex(txid string) (string, error) {
if hex, ok := e.cache[txid]; ok {
return hex, nil
}
txHex, err := e.getTxHex(txid)
if err != nil {
return "", err
}
e.cache[txid] = txHex
return txHex, nil
}
func (e *explorer) Broadcast(txStr string) (string, error) {
tx, err := transaction.NewTxFromHex(txStr)
if err != nil {
pset, err := psetv2.NewPsetFromBase64(txStr)
if err != nil {
return "", err
}
tx, err = psetv2.Extract(pset)
if err != nil {
return "", err
}
txStr, _ = tx.ToHex()
}
txid := tx.TxHash().String()
e.cache[txid] = txStr
txid, err = e.broadcast(txStr)
if err != nil {
if strings.Contains(
strings.ToLower(err.Error()), "transaction already in block chain",
) {
return txid, nil
}
return "", err
}
return txid, nil
}
func (e *explorer) GetUtxos(addr string) ([]utxo, error) {
resp, err := http.Get(fmt.Sprintf("%s/address/%s/utxo", e.baseUrl, addr))
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf(string(body))
}
payload := []utxo{}
if err := json.Unmarshal(body, &payload); err != nil {
return nil, err
}
return payload, nil
}
func (e *explorer) GetBalance(addr, asset string) (uint64, error) {
payload, err := e.GetUtxos(addr)
if err != nil {
return 0, err
}
balance := uint64(0)
for _, p := range payload {
if p.Asset != asset {
continue
}
balance += p.Amount
}
return balance, nil
}
func (e *explorer) GetRedeemedVtxosBalance(
addr string, unilateralExitDelay int64,
) (spendableBalance uint64, lockedBalance map[int64]uint64, err error) {
utxos, err := e.GetUtxos(addr)
if err != nil {
return
}
lockedBalance = make(map[int64]uint64, 0)
now := time.Now()
for _, utxo := range utxos {
blocktime := now
if utxo.Status.Confirmed {
blocktime = time.Unix(utxo.Status.Blocktime, 0)
}
delay := time.Duration(unilateralExitDelay) * time.Second
availableAt := blocktime.Add(delay)
if availableAt.After(now) {
if _, ok := lockedBalance[availableAt.Unix()]; !ok {
lockedBalance[availableAt.Unix()] = 0
}
lockedBalance[availableAt.Unix()] += utxo.Amount
} else {
spendableBalance += utxo.Amount
}
}
return
}
func (e *explorer) GetTxBlockTime(
txid string,
) (confirmed bool, blocktime int64, err error) {
resp, err := http.Get(fmt.Sprintf("%s/tx/%s", e.baseUrl, txid))
if err != nil {
return false, 0, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return false, 0, err
}
if resp.StatusCode != http.StatusOK {
return false, 0, fmt.Errorf(string(body))
}
var tx struct {
Status struct {
Confirmed bool `json:"confirmed"`
Blocktime int64 `json:"block_time"`
} `json:"status"`
}
if err := json.Unmarshal(body, &tx); err != nil {
return false, 0, err
}
if !tx.Status.Confirmed {
return false, -1, nil
}
return true, tx.Status.Blocktime, nil
}
func (e *explorer) getTxHex(txid string) (string, error) {
resp, err := http.Get(fmt.Sprintf("%s/tx/%s/hex", e.baseUrl, txid))
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf(string(body))
}
hex := string(body)
e.cache[txid] = hex
return hex, nil
}
func (e *explorer) broadcast(txHex string) (string, error) {
body := bytes.NewBuffer([]byte(txHex))
resp, err := http.Post(fmt.Sprintf("%s/tx", e.baseUrl), "text/plain", body)
if err != nil {
return "", err
}
defer resp.Body.Close()
bodyResponse, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf(string(bodyResponse))
}
return string(bodyResponse), nil
}

60
pkg/client-sdk/go.mod Normal file
View File

@@ -0,0 +1,60 @@
module github.com/ark-network/ark-sdk
go 1.22.2
replace github.com/ark-network/ark/common => ./../../common
replace github.com/ark-network/ark => ./../../server
require (
github.com/ark-network/ark v0.0.0-00010101000000-000000000000
github.com/ark-network/ark/common v0.0.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/btcec/v2 v2.3.4
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0
github.com/go-openapi/errors v0.22.0
github.com/go-openapi/runtime v0.28.0
github.com/go-openapi/strfmt v0.23.0
github.com/go-openapi/swag v0.23.0
github.com/go-openapi/validate v0.24.0
github.com/sirupsen/logrus v1.9.3
github.com/vulpemventures/go-elements v0.5.3
google.golang.org/grpc v1.65.0
)
require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/btcsuite/btcd/btcutil v1.1.5 // indirect
github.com/btcsuite/btcd/btcutil/psbt v1.1.9 // indirect
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f // indirect
github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
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/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.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/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

206
pkg/client-sdk/go.sum Normal file
View File

@@ -0,0 +1,206 @@
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
github.com/btcsuite/btcd v0.24.2 h1:aLmxPguqxza+4ag8R1I2nnJjSu2iFn/kqtHTIImswcY=
github.com/btcsuite/btcd v0.24.2/go.mod h1:5C8ChTkl5ejr3WHj8tkQSCmydiMEPB0ZhQhehpq7Dgg=
github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA=
github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE=
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A=
github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE=
github.com/btcsuite/btcd/btcutil v1.1.5 h1:+wER79R5670vs/ZusMTF1yTcRYE5GUsFbdjdisflzM8=
github.com/btcsuite/btcd/btcutil v1.1.5/go.mod h1:PSZZ4UitpLBWzxGd5VGOrLnmOjtPP/a6HaFo12zMs00=
github.com/btcsuite/btcd/btcutil/psbt v1.1.9 h1:UmfOIiWMZcVMOLaN+lxbbLSuoINGS1WmK1TZNI0b4yk=
github.com/btcsuite/btcd/btcutil/psbt v1.1.9/go.mod h1:ehBEvU91lxSlXtA+zZz3iFYx7Yq9eqnKx4/kSrnsvMY=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 h1:59Kx4K6lzOW5w6nFlA0v5+lk/6sjybR934QNHSJZPTQ=
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I=
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC03zFCU=
github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo=
github.com/go-openapi/errors v0.22.0 h1:c4xY/OLxUBSTiepAg3j/MHuAv5mJhnf53LLMWFB+u/w=
github.com/go-openapi/errors v0.22.0/go.mod h1:J3DmZScxCDufmIMsdOuDHxJbdOGC0xtUynjIx092vXE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
github.com/go-openapi/loads v0.22.0 h1:ECPGd4jX1U6NApCGG1We+uEozOAvXvJSF4nnwHZ8Aco=
github.com/go-openapi/loads v0.22.0/go.mod h1:yLsaTCS92mnSAZX5WWoxszLj0u+Ojl+Zs5Stn1oF+rs=
github.com/go-openapi/runtime v0.28.0 h1:gpPPmWSNGo214l6n8hzdXYhPuJcGtziTOgUpvsFWGIQ=
github.com/go-openapi/runtime v0.28.0/go.mod h1:QN7OzcS+XuYmkQLw05akXk0jRH/eZ3kb18+1KwW9gyc=
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3BumrGD58=
github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941 h1:CTcw80hz/Sw8hqlKX5ZYvBUF5gAHSHwdjXxRf/cjDcI=
github.com/vulpemventures/fastsha256 v0.0.0-20160815193821-637e65642941/go.mod h1:GXBJykxW2kUcktGdsgyay7uwwWvkljASfljNcT0mbh8=
github.com/vulpemventures/go-elements v0.5.3 h1:zaC/ynHFwCAzFSOMfzb6BcbD6FXASppSiGMycc95WVA=
github.com/vulpemventures/go-elements v0.5.3/go.mod h1:aBGuWXHaiAIUIcwqCdtEh2iQ3kJjKwHU9ywvhlcRSeU=
github.com/vulpemventures/go-secp256k1-zkp v1.1.6 h1:BmsrmXRLUibwa75Qkk8yELjpzCzlAjYFGLiLiOdq7Xo=
github.com/vulpemventures/go-secp256k1-zkp v1.1.6/go.mod h1:zo7CpgkuPgoe7fAV+inyxsI9IhGmcoFgyD8nqZaPSOM=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
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/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/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=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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/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/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=
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 h1:7whR9kGa5LUwFtpLm2ArCEejtnxlGeLbAyjFY8sGNFw=
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157/go.mod h1:99sLkeliLXfdj2J75X3Ho+rrVCaJze0uwN7zDDkjPVU=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 h1:Zy9XzmMEflZ/MAaA7vNcoebnRAld7FsPW1EeBB7V0m8=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157/go.mod h1:EfXuqaE1J41VCDicxHzUDm+8rk+7ZdXzHV0IhO/I6s0=
google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc=
google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -0,0 +1,63 @@
package arkgrpcclient
import (
"errors"
"fmt"
"strings"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
)
var (
errAspUrlEmpty = errors.New("asp url is empty")
)
func New(aspUrl string) (ArkGrpcClient, func(), error) {
if aspUrl == "" {
return nil, nil, errAspUrlEmpty
}
creds := insecure.NewCredentials()
port := 80
if strings.HasPrefix(aspUrl, "https://") {
aspUrl = strings.TrimPrefix(aspUrl, "https://")
creds = credentials.NewTLS(nil)
port = 443
}
if !strings.Contains(aspUrl, ":") {
aspUrl = fmt.Sprintf("%s:%d", aspUrl, port)
}
conn, err := grpc.NewClient(aspUrl, grpc.WithTransportCredentials(creds))
if err != nil {
return nil, nil, err
}
closeFn := func() {
err := conn.Close()
if err != nil {
fmt.Printf("error closing connection: %s\n", err)
}
}
return &arkGrpcClient{conn: conn}, closeFn, nil
}
type ArkGrpcClient interface {
Admin() arkv1.AdminServiceClient
Service() arkv1.ArkServiceClient
}
type arkGrpcClient struct {
conn *grpc.ClientConn
}
func (a *arkGrpcClient) Admin() arkv1.AdminServiceClient {
return arkv1.NewAdminServiceClient(a.conn)
}
func (a *arkGrpcClient) Service() arkv1.ArkServiceClient {
return arkv1.NewArkServiceClient(a.conn)
}

View File

@@ -0,0 +1,814 @@
package arksdk
import (
"context"
"errors"
"net/url"
"strconv"
"time"
arkgrpcclient "github.com/ark-network/ark-sdk/grpc"
"github.com/ark-network/ark-sdk/rest/service/arkservicerestclient"
"github.com/ark-network/ark-sdk/rest/service/arkservicerestclient/ark_service"
"github.com/ark-network/ark-sdk/rest/service/models"
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
"github.com/ark-network/ark/common/tree"
httptransport "github.com/go-openapi/runtime/client"
"github.com/go-openapi/strfmt"
"github.com/vulpemventures/go-elements/psetv2"
)
type arkTransportClient interface {
getInfo(ctx context.Context) (*arkv1.GetInfoResponse, error)
listVtxos(ctx context.Context, addr string) (*arkv1.ListVtxosResponse, error)
getSpendableVtxos(
ctx context.Context, addr string, computeExpiryDetails bool,
) ([]vtxo, error)
getRound(ctx context.Context, txID string) (*arkv1.GetRoundResponse, error)
getRoundByID(ctx context.Context, roundID string) (*arkv1.GetRoundByIdResponse, error)
getRedeemBranches(
ctx context.Context,
explorer Explorer,
vtxos []vtxo,
) (map[string]*redeemBranch, error)
getOffchainBalance(
ctx context.Context, addr string, computeExpiration bool,
) (uint64, map[int64]uint64, error)
onboard(
ctx context.Context, req *arkv1.OnboardRequest,
) (*arkv1.OnboardResponse, error)
registerPayment(
ctx context.Context, req *arkv1.RegisterPaymentRequest,
) (*arkv1.RegisterPaymentResponse, error)
claimPayment(
ctx context.Context, req *arkv1.ClaimPaymentRequest,
) (*arkv1.ClaimPaymentResponse, error)
getEventStream(
ctx context.Context, paymentID string, req *arkv1.GetEventStreamRequest,
) (*EventStream, error)
ping(ctx context.Context, req *arkv1.PingRequest) (*arkv1.PingResponse, error)
finalizePayment(
ctx context.Context, req *arkv1.FinalizePaymentRequest,
) (*arkv1.FinalizePaymentResponse, error)
setExplorerSvc(explorerSvc Explorer)
}
func newArkTransportClient(
aspUrl string, protocol TransportProtocol, explorer Explorer,
) (arkTransportClient, error) {
switch protocol {
case Grpc:
grpcClient, closeFn, err := newGrpcClient(aspUrl)
if err != nil {
return nil, err
}
return &arkInnerClient{
grpcClient: grpcClient,
grpcCloseFn: closeFn,
explorerSvc: explorer,
eventStream: &EventStream{
eventResp: make(chan *arkv1.GetEventStreamResponse),
err: make(chan error),
},
}, nil
case Rest:
resClient, err := newRestClient(aspUrl)
if err != nil {
return nil, err
}
return &arkInnerClient{
resClient: resClient,
explorerSvc: explorer,
eventStream: &EventStream{
eventResp: make(chan *arkv1.GetEventStreamResponse),
err: make(chan error),
},
}, nil
default:
return nil, errors.New("unknown protocol")
}
}
type arkInnerClient struct {
grpcClient arkgrpcclient.ArkGrpcClient
grpcCloseFn func()
resClient *arkservicerestclient.ArkV1ServiceProto
explorerSvc Explorer
eventStream *EventStream
}
func (a *arkInnerClient) setExplorerSvc(explorerSvc Explorer) {
a.explorerSvc = explorerSvc
}
type EventStream struct {
eventResp chan *arkv1.GetEventStreamResponse
err chan error
}
func (a *arkInnerClient) getEventStream(
ctx context.Context, paymentID string, req *arkv1.GetEventStreamRequest,
) (*EventStream, error) {
switch {
case a.grpcClient != nil:
stream, err := a.grpcClient.Service().GetEventStream(ctx, req)
if err != nil {
return nil, err
}
go func() {
defer close(a.eventStream.eventResp)
defer close(a.eventStream.err)
for {
resp, err := stream.Recv()
if err != nil {
a.eventStream.err <- err
return
}
a.eventStream.eventResp <- resp
}
}()
case a.resClient != nil:
go func(payID string) {
defer close(a.eventStream.eventResp)
defer close(a.eventStream.err)
timeout := time.After(30 * time.Second) // TODO make this configurable
mainloop:
for {
select {
case <-timeout:
a.eventStream.err <- errors.New("timeout reached")
break mainloop
default:
resp, err := a.ping(ctx, &arkv1.PingRequest{
PaymentId: payID,
})
if err != nil {
a.eventStream.err <- err
}
if resp.GetEvent() != nil {
levels := make([]*arkv1.TreeLevel, 0, len(resp.GetEvent().GetCongestionTree().GetLevels()))
for _, l := range resp.GetEvent().GetCongestionTree().GetLevels() {
nodes := make([]*arkv1.Node, 0, len(l.Nodes))
for _, n := range l.Nodes {
nodes = append(nodes, &arkv1.Node{
Txid: n.Txid,
Tx: n.Tx,
ParentTxid: n.ParentTxid,
})
}
levels = append(levels, &arkv1.TreeLevel{
Nodes: nodes,
})
}
a.eventStream.eventResp <- &arkv1.GetEventStreamResponse{
Event: &arkv1.GetEventStreamResponse_RoundFinalization{
RoundFinalization: &arkv1.RoundFinalizationEvent{
Id: resp.GetEvent().GetId(),
PoolTx: resp.GetEvent().GetPoolTx(),
ForfeitTxs: resp.GetEvent().GetForfeitTxs(),
CongestionTree: &arkv1.Tree{
Levels: levels,
},
Connectors: resp.GetEvent().GetConnectors(),
},
},
}
for {
roundID := resp.GetEvent().GetId()
round, err := a.getRoundByID(ctx, roundID)
if err != nil {
a.eventStream.err <- err
}
if round.GetRound().GetStage() == arkv1.RoundStage_ROUND_STAGE_FINALIZED {
ptx, _ := psetv2.NewPsetFromBase64(round.GetRound().GetPoolTx())
utx, _ := ptx.UnsignedTx()
a.eventStream.eventResp <- &arkv1.GetEventStreamResponse{
Event: &arkv1.GetEventStreamResponse_RoundFinalized{
RoundFinalized: &arkv1.RoundFinalizedEvent{
PoolTxid: utx.TxHash().String(),
},
},
}
break mainloop
}
if round.GetRound().GetStage() == arkv1.RoundStage_ROUND_STAGE_FAILED {
a.eventStream.eventResp <- &arkv1.GetEventStreamResponse{
Event: &arkv1.GetEventStreamResponse_RoundFailed{
RoundFailed: &arkv1.RoundFailed{
Id: round.GetRound().GetId(),
Reason: "unknown reason", //TODO getRoundByID should return the reason
},
},
}
break mainloop
}
time.Sleep(1 * time.Second)
}
}
time.Sleep(1 * time.Second)
}
}
}(paymentID)
}
return a.eventStream, nil
}
func (a *arkInnerClient) getInfo(ctx context.Context) (*arkv1.GetInfoResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().GetInfo(ctx, &arkv1.GetInfoRequest{})
case a.resClient != nil:
resp, err := a.resClient.ArkService.ArkServiceGetInfo(ark_service.NewArkServiceGetInfoParams())
if err != nil {
return nil, err
}
roundLifetime, err := strconv.Atoi(resp.Payload.RoundLifetime)
if err != nil {
return nil, err
}
unilateralExitDelay, err := strconv.Atoi(resp.Payload.UnilateralExitDelay)
if err != nil {
return nil, err
}
roundInterval, err := strconv.Atoi(resp.Payload.RoundInterval)
if err != nil {
return nil, err
}
minRelayFee, err := strconv.Atoi(resp.Payload.MinRelayFee)
if err != nil {
return nil, err
}
return &arkv1.GetInfoResponse{
Pubkey: resp.Payload.Pubkey,
RoundLifetime: int64(roundLifetime),
UnilateralExitDelay: int64(unilateralExitDelay),
RoundInterval: int64(roundInterval),
Network: resp.Payload.Network,
MinRelayFee: int64(minRelayFee),
}, nil
}
return nil, nil
}
func (a *arkInnerClient) listVtxos(
ctx context.Context,
addr string,
) (*arkv1.ListVtxosResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().ListVtxos(
ctx, &arkv1.ListVtxosRequest{
Address: addr,
},
)
case a.resClient != nil:
resp, err := a.resClient.ArkService.ArkServiceListVtxos(
ark_service.NewArkServiceListVtxosParams().WithAddress(addr),
)
if err != nil {
return nil, err
}
vtxos := make([]*arkv1.Vtxo, 0, len(resp.Payload.SpendableVtxos))
for _, v := range resp.Payload.SpendableVtxos {
expAt, err := strconv.Atoi(v.ExpireAt)
if err != nil {
return nil, err
}
amount, err := strconv.Atoi(v.Receiver.Amount)
if err != nil {
return nil, err
}
vtxos = append(vtxos, &arkv1.Vtxo{
Outpoint: &arkv1.Input{
Txid: v.Outpoint.Txid,
Vout: uint32(v.Outpoint.Vout),
},
Receiver: &arkv1.Output{
Address: v.Receiver.Address,
Amount: uint64(amount),
},
Spent: v.Spent,
PoolTxid: v.PoolTxid,
SpentBy: v.SpentBy,
ExpireAt: int64(expAt),
Swept: v.Swept,
})
}
return &arkv1.ListVtxosResponse{
SpendableVtxos: vtxos,
}, nil
}
return nil, nil
}
func (a *arkInnerClient) getRound(
ctx context.Context, txID string,
) (*arkv1.GetRoundResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().GetRound(
ctx, &arkv1.GetRoundRequest{
Txid: txID,
},
)
case a.resClient != nil:
resp, err := a.resClient.ArkService.ArkServiceGetRound(
ark_service.NewArkServiceGetRoundParams().WithTxid(txID),
)
if err != nil {
return nil, err
}
start, err := strconv.Atoi(resp.Payload.Round.Start)
if err != nil {
return nil, err
}
end, err := strconv.Atoi(resp.Payload.Round.End)
if err != nil {
return nil, err
}
levels := make([]*arkv1.TreeLevel, 0, len(resp.Payload.Round.CongestionTree.Levels))
for _, l := range resp.Payload.Round.CongestionTree.Levels {
nodes := make([]*arkv1.Node, 0, len(l.Nodes))
for _, n := range l.Nodes {
nodes = append(nodes, &arkv1.Node{
Txid: n.Txid,
Tx: n.Tx,
ParentTxid: n.ParentTxid,
})
}
levels = append(levels, &arkv1.TreeLevel{
Nodes: nodes,
})
}
return &arkv1.GetRoundResponse{
Round: &arkv1.Round{
Id: resp.Payload.Round.ID,
Start: int64(start),
End: int64(end),
PoolTx: resp.Payload.Round.PoolTx,
CongestionTree: &arkv1.Tree{
Levels: levels,
},
ForfeitTxs: resp.Payload.Round.ForfeitTxs,
Connectors: resp.Payload.Round.Connectors,
},
}, nil
}
return nil, nil
}
func (a *arkInnerClient) getSpendableVtxos(
ctx context.Context, addr string, computeExpiryDetails bool,
) ([]vtxo, error) {
allVtxos, err := a.listVtxos(ctx, addr)
if err != nil {
return nil, err
}
vtxos := make([]vtxo, 0, len(allVtxos.GetSpendableVtxos()))
for _, v := range allVtxos.GetSpendableVtxos() {
var expireAt *time.Time
if v.ExpireAt > 0 {
t := time.Unix(v.ExpireAt, 0)
expireAt = &t
}
if v.Swept {
continue
}
vtxos = append(vtxos, vtxo{
amount: v.Receiver.Amount,
txid: v.Outpoint.Txid,
vout: v.Outpoint.Vout,
poolTxid: v.PoolTxid,
expireAt: expireAt,
})
}
if !computeExpiryDetails {
return vtxos, nil
}
redeemBranches, err := a.getRedeemBranches(ctx, a.explorerSvc, vtxos)
if err != nil {
return nil, err
}
for vtxoTxid, branch := range redeemBranches {
expiration, err := branch.expireAt(a.explorerSvc)
if err != nil {
return nil, err
}
for i, vtxo := range vtxos {
if vtxo.txid == vtxoTxid {
vtxos[i].expireAt = expiration
break
}
}
}
return vtxos, nil
}
type vtxo struct {
amount uint64
txid string
vout uint32
poolTxid string
expireAt *time.Time
}
func newGrpcClient(
aspUrl string,
) (arkgrpcclient.ArkGrpcClient, func(), error) {
return arkgrpcclient.New(aspUrl)
}
func newRestClient(
serviceURL string,
) (*arkservicerestclient.ArkV1ServiceProto, error) {
parsedURL, err := url.Parse(serviceURL)
if err != nil {
return nil, err
}
schemes := []string{parsedURL.Scheme}
host := parsedURL.Host
basePath := parsedURL.Path
if basePath == "" {
basePath = arkservicerestclient.DefaultBasePath
}
cfg := &arkservicerestclient.TransportConfig{
Host: host,
BasePath: basePath,
Schemes: schemes,
}
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
return arkservicerestclient.New(transport, strfmt.Default), nil
}
func (a *arkInnerClient) getRedeemBranches(
ctx context.Context,
explorer Explorer,
vtxos []vtxo,
) (map[string]*redeemBranch, error) {
congestionTrees := make(map[string]tree.CongestionTree, 0)
redeemBranches := make(map[string]*redeemBranch, 0)
for _, vtxo := range vtxos {
if _, ok := congestionTrees[vtxo.poolTxid]; !ok {
round, err := a.getRound(ctx, vtxo.poolTxid)
if err != nil {
return nil, err
}
treeFromRound := round.GetRound().GetCongestionTree()
congestionTree, err := toCongestionTree(treeFromRound)
if err != nil {
return nil, err
}
congestionTrees[vtxo.poolTxid] = congestionTree
}
redeemBranch, err := newRedeemBranch(
explorer, congestionTrees[vtxo.poolTxid], vtxo,
)
if err != nil {
return nil, err
}
redeemBranches[vtxo.txid] = redeemBranch
}
return redeemBranches, nil
}
func (a *arkInnerClient) getOffchainBalance(
ctx context.Context, addr string, computeExpiration bool,
) (uint64, map[int64]uint64, error) {
amountByExpiration := make(map[int64]uint64, 0)
vtxos, err := a.getSpendableVtxos(ctx, addr, computeExpiration)
if err != nil {
return 0, nil, err
}
var balance uint64
for _, vtxo := range vtxos {
balance += vtxo.amount
if vtxo.expireAt != nil {
expiration := vtxo.expireAt.Unix()
if _, ok := amountByExpiration[expiration]; !ok {
amountByExpiration[expiration] = 0
}
amountByExpiration[expiration] += vtxo.amount
}
}
return balance, amountByExpiration, nil
}
func (a *arkInnerClient) onboard(
ctx context.Context, req *arkv1.OnboardRequest,
) (*arkv1.OnboardResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().Onboard(ctx, req)
case a.resClient != nil:
levels := make([]*models.V1TreeLevel, 0, len(req.GetCongestionTree().GetLevels()))
for _, l := range req.GetCongestionTree().GetLevels() {
nodes := make([]*models.V1Node, 0, len(l.GetNodes()))
for _, n := range l.GetNodes() {
nodes = append(nodes, &models.V1Node{
Txid: n.GetTxid(),
Tx: n.GetTx(),
ParentTxid: n.GetParentTxid(),
})
}
levels = append(levels, &models.V1TreeLevel{
Nodes: nodes,
})
}
congestionTree := models.V1Tree{
Levels: levels,
}
body := models.V1OnboardRequest{
BoardingTx: req.GetBoardingTx(),
CongestionTree: &congestionTree,
UserPubkey: req.GetUserPubkey(),
}
_, err := a.resClient.ArkService.ArkServiceOnboard(
ark_service.NewArkServiceOnboardParams().WithBody(&body),
)
if err != nil {
return nil, err
}
return &arkv1.OnboardResponse{}, nil
}
return nil, nil
}
func (a *arkInnerClient) registerPayment(
ctx context.Context, req *arkv1.RegisterPaymentRequest,
) (*arkv1.RegisterPaymentResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().RegisterPayment(ctx, req)
case a.resClient != nil:
inputs := make([]*models.V1Input, 0, len(req.GetInputs()))
for _, i := range req.GetInputs() {
inputs = append(inputs, &models.V1Input{
Txid: i.GetTxid(),
Vout: int64(i.GetVout()),
})
}
body := models.V1RegisterPaymentRequest{
Inputs: inputs,
}
resp, err := a.resClient.ArkService.ArkServiceRegisterPayment(
ark_service.NewArkServiceRegisterPaymentParams().WithBody(&body),
)
if err != nil {
return nil, err
}
return &arkv1.RegisterPaymentResponse{
Id: resp.Payload.ID,
}, nil
}
return nil, nil
}
func (a *arkInnerClient) claimPayment(
ctx context.Context, req *arkv1.ClaimPaymentRequest,
) (*arkv1.ClaimPaymentResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().ClaimPayment(ctx, req)
case a.resClient != nil:
outputs := make([]*models.V1Output, 0, len(req.GetOutputs()))
for _, o := range req.GetOutputs() {
outputs = append(outputs, &models.V1Output{
Address: o.GetAddress(),
Amount: strconv.Itoa(int(o.GetAmount())),
})
}
body := models.V1ClaimPaymentRequest{
ID: req.GetId(),
Outputs: outputs,
}
_, err := a.resClient.ArkService.ArkServiceClaimPayment(
ark_service.NewArkServiceClaimPaymentParams().WithBody(&body),
)
if err != nil {
return nil, err
}
return &arkv1.ClaimPaymentResponse{}, nil
}
return nil, nil
}
func (a *arkInnerClient) ping(
ctx context.Context, req *arkv1.PingRequest,
) (*arkv1.PingResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().Ping(ctx, req)
case a.resClient != nil:
r := ark_service.NewArkServicePingParams()
r.SetPaymentID(req.GetPaymentId())
resp, err := a.resClient.ArkService.ArkServicePing(r)
if err != nil {
return nil, err
}
var event *arkv1.RoundFinalizationEvent
if resp.Payload.Event != nil &&
resp.Payload.Event.ID != "" &&
len(resp.Payload.Event.ForfeitTxs) > 0 &&
len(resp.Payload.Event.CongestionTree.Levels) > 0 &&
len(resp.Payload.Event.Connectors) > 0 &&
resp.Payload.Event.PoolTx != "" {
levels := make([]*arkv1.TreeLevel, 0, len(resp.Payload.Event.CongestionTree.Levels))
for _, l := range resp.Payload.Event.CongestionTree.Levels {
nodes := make([]*arkv1.Node, 0, len(l.Nodes))
for _, n := range l.Nodes {
nodes = append(nodes, &arkv1.Node{
Txid: n.Txid,
Tx: n.Tx,
ParentTxid: n.ParentTxid,
})
}
levels = append(levels, &arkv1.TreeLevel{
Nodes: nodes,
})
}
event = &arkv1.RoundFinalizationEvent{
Id: resp.Payload.Event.ID,
PoolTx: resp.Payload.Event.PoolTx,
ForfeitTxs: resp.Payload.Event.ForfeitTxs,
CongestionTree: &arkv1.Tree{
Levels: levels,
},
Connectors: resp.Payload.Event.Connectors,
}
}
return &arkv1.PingResponse{
ForfeitTxs: resp.Payload.ForfeitTxs,
Event: event,
}, nil
}
return nil, nil
}
func (a *arkInnerClient) finalizePayment(
ctx context.Context, req *arkv1.FinalizePaymentRequest,
) (*arkv1.FinalizePaymentResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().FinalizePayment(ctx, req)
case a.resClient != nil:
body := models.V1FinalizePaymentRequest{
SignedForfeitTxs: req.GetSignedForfeitTxs(),
}
_, err := a.resClient.ArkService.ArkServiceFinalizePayment(
ark_service.NewArkServiceFinalizePaymentParams().WithBody(&body),
)
if err != nil {
return nil, err
}
return &arkv1.FinalizePaymentResponse{}, nil
}
return nil, nil
}
func (a *arkInnerClient) getRoundByID(
ctx context.Context, roundID string,
) (*arkv1.GetRoundByIdResponse, error) {
switch {
case a.grpcClient != nil:
return a.grpcClient.Service().GetRoundById(ctx, &arkv1.GetRoundByIdRequest{
Id: roundID,
})
case a.resClient != nil:
resp, err := a.resClient.ArkService.ArkServiceGetRoundByID(
ark_service.NewArkServiceGetRoundByIDParams().WithID(roundID),
)
if err != nil {
return nil, err
}
start, err := strconv.Atoi(resp.Payload.Round.Start)
if err != nil {
return nil, err
}
end, err := strconv.Atoi(resp.Payload.Round.End)
if err != nil {
return nil, err
}
levels := make([]*arkv1.TreeLevel, 0, len(resp.Payload.Round.CongestionTree.Levels))
for _, l := range resp.Payload.Round.CongestionTree.Levels {
nodes := make([]*arkv1.Node, 0, len(l.Nodes))
for _, n := range l.Nodes {
nodes = append(nodes, &arkv1.Node{
Txid: n.Txid,
Tx: n.Tx,
ParentTxid: n.ParentTxid,
})
}
levels = append(levels, &arkv1.TreeLevel{
Nodes: nodes,
})
}
stage := stageStrToInt(resp.Payload.Round.Stage)
return &arkv1.GetRoundByIdResponse{
Round: &arkv1.Round{
Id: resp.Payload.Round.ID,
Start: int64(start),
End: int64(end),
PoolTx: resp.Payload.Round.PoolTx,
CongestionTree: &arkv1.Tree{
Levels: levels,
},
ForfeitTxs: resp.Payload.Round.ForfeitTxs,
Connectors: resp.Payload.Round.Connectors,
Stage: arkv1.RoundStage(stage),
},
}, nil
}
return nil, nil
}
func stageStrToInt(stage models.V1RoundStage) int {
switch stage {
case models.V1RoundStageROUNDSTAGEUNSPECIFIED:
return 0
case models.V1RoundStageROUNDSTAGEREGISTRATION:
return 1
case models.V1RoundStageROUNDSTAGEFINALIZATION:
return 2
case models.V1RoundStageROUNDSTAGEFINALIZED:
return 3
case models.V1RoundStageROUNDSTAGEFAILED:
return 4
}
return -1
}

View File

@@ -0,0 +1,142 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// New creates a new admin service API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
return &Client{transport: transport, formats: formats}
}
/*
Client for admin service API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
/*
AdminServiceGetBalance admin service get balance API
*/
func (a *Client) AdminServiceGetBalance(params *AdminServiceGetBalanceParams) (*AdminServiceGetBalanceOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewAdminServiceGetBalanceParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "AdminService_GetBalance",
Method: "GET",
PathPattern: "/v1/admin/balance",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &AdminServiceGetBalanceReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*AdminServiceGetBalanceOK), nil
}
/*
AdminServiceGetRoundDetails admin service get round details API
*/
func (a *Client) AdminServiceGetRoundDetails(params *AdminServiceGetRoundDetailsParams) (*AdminServiceGetRoundDetailsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewAdminServiceGetRoundDetailsParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "AdminService_GetRoundDetails",
Method: "GET",
PathPattern: "/v1/admin/round/{roundId}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &AdminServiceGetRoundDetailsReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*AdminServiceGetRoundDetailsOK), nil
}
/*
AdminServiceGetRounds admin service get rounds API
*/
func (a *Client) AdminServiceGetRounds(params *AdminServiceGetRoundsParams) (*AdminServiceGetRoundsOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewAdminServiceGetRoundsParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "AdminService_GetRounds",
Method: "POST",
PathPattern: "/v1/admin/rounds",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &AdminServiceGetRoundsReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*AdminServiceGetRoundsOK), nil
}
/*
AdminServiceGetScheduledSweep admin service get scheduled sweep API
*/
func (a *Client) AdminServiceGetScheduledSweep(params *AdminServiceGetScheduledSweepParams) (*AdminServiceGetScheduledSweepOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewAdminServiceGetScheduledSweepParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "AdminService_GetScheduledSweep",
Method: "GET",
PathPattern: "/v1/admin/sweeps",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &AdminServiceGetScheduledSweepReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*AdminServiceGetScheduledSweepOK), nil
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View File

@@ -0,0 +1,113 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewAdminServiceGetBalanceParams creates a new AdminServiceGetBalanceParams object
// with the default values initialized.
func NewAdminServiceGetBalanceParams() *AdminServiceGetBalanceParams {
return &AdminServiceGetBalanceParams{
timeout: cr.DefaultTimeout,
}
}
// NewAdminServiceGetBalanceParamsWithTimeout creates a new AdminServiceGetBalanceParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewAdminServiceGetBalanceParamsWithTimeout(timeout time.Duration) *AdminServiceGetBalanceParams {
return &AdminServiceGetBalanceParams{
timeout: timeout,
}
}
// NewAdminServiceGetBalanceParamsWithContext creates a new AdminServiceGetBalanceParams object
// with the default values initialized, and the ability to set a context for a request
func NewAdminServiceGetBalanceParamsWithContext(ctx context.Context) *AdminServiceGetBalanceParams {
return &AdminServiceGetBalanceParams{
Context: ctx,
}
}
// NewAdminServiceGetBalanceParamsWithHTTPClient creates a new AdminServiceGetBalanceParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewAdminServiceGetBalanceParamsWithHTTPClient(client *http.Client) *AdminServiceGetBalanceParams {
return &AdminServiceGetBalanceParams{
HTTPClient: client,
}
}
/*AdminServiceGetBalanceParams contains all the parameters to send to the API endpoint
for the admin service get balance operation typically these are written to a http.Request
*/
type AdminServiceGetBalanceParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the admin service get balance params
func (o *AdminServiceGetBalanceParams) WithTimeout(timeout time.Duration) *AdminServiceGetBalanceParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the admin service get balance params
func (o *AdminServiceGetBalanceParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the admin service get balance params
func (o *AdminServiceGetBalanceParams) WithContext(ctx context.Context) *AdminServiceGetBalanceParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the admin service get balance params
func (o *AdminServiceGetBalanceParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the admin service get balance params
func (o *AdminServiceGetBalanceParams) WithHTTPClient(client *http.Client) *AdminServiceGetBalanceParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the admin service get balance params
func (o *AdminServiceGetBalanceParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *AdminServiceGetBalanceParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/admin/models"
)
// AdminServiceGetBalanceReader is a Reader for the AdminServiceGetBalance structure.
type AdminServiceGetBalanceReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *AdminServiceGetBalanceReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewAdminServiceGetBalanceOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewAdminServiceGetBalanceDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewAdminServiceGetBalanceOK creates a AdminServiceGetBalanceOK with default headers values
func NewAdminServiceGetBalanceOK() *AdminServiceGetBalanceOK {
return &AdminServiceGetBalanceOK{}
}
/*AdminServiceGetBalanceOK handles this case with default header values.
A successful response.
*/
type AdminServiceGetBalanceOK struct {
Payload *models.V1GetBalanceResponse
}
func (o *AdminServiceGetBalanceOK) Error() string {
return fmt.Sprintf("[GET /v1/admin/balance][%d] adminServiceGetBalanceOK %+v", 200, o.Payload)
}
func (o *AdminServiceGetBalanceOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1GetBalanceResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewAdminServiceGetBalanceDefault creates a AdminServiceGetBalanceDefault with default headers values
func NewAdminServiceGetBalanceDefault(code int) *AdminServiceGetBalanceDefault {
return &AdminServiceGetBalanceDefault{
_statusCode: code,
}
}
/*AdminServiceGetBalanceDefault handles this case with default header values.
An unexpected error response.
*/
type AdminServiceGetBalanceDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the admin service get balance default response
func (o *AdminServiceGetBalanceDefault) Code() int {
return o._statusCode
}
func (o *AdminServiceGetBalanceDefault) Error() string {
return fmt.Sprintf("[GET /v1/admin/balance][%d] AdminService_GetBalance default %+v", o._statusCode, o.Payload)
}
func (o *AdminServiceGetBalanceDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewAdminServiceGetRoundDetailsParams creates a new AdminServiceGetRoundDetailsParams object
// with the default values initialized.
func NewAdminServiceGetRoundDetailsParams() *AdminServiceGetRoundDetailsParams {
var ()
return &AdminServiceGetRoundDetailsParams{
timeout: cr.DefaultTimeout,
}
}
// NewAdminServiceGetRoundDetailsParamsWithTimeout creates a new AdminServiceGetRoundDetailsParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewAdminServiceGetRoundDetailsParamsWithTimeout(timeout time.Duration) *AdminServiceGetRoundDetailsParams {
var ()
return &AdminServiceGetRoundDetailsParams{
timeout: timeout,
}
}
// NewAdminServiceGetRoundDetailsParamsWithContext creates a new AdminServiceGetRoundDetailsParams object
// with the default values initialized, and the ability to set a context for a request
func NewAdminServiceGetRoundDetailsParamsWithContext(ctx context.Context) *AdminServiceGetRoundDetailsParams {
var ()
return &AdminServiceGetRoundDetailsParams{
Context: ctx,
}
}
// NewAdminServiceGetRoundDetailsParamsWithHTTPClient creates a new AdminServiceGetRoundDetailsParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewAdminServiceGetRoundDetailsParamsWithHTTPClient(client *http.Client) *AdminServiceGetRoundDetailsParams {
var ()
return &AdminServiceGetRoundDetailsParams{
HTTPClient: client,
}
}
/*AdminServiceGetRoundDetailsParams contains all the parameters to send to the API endpoint
for the admin service get round details operation typically these are written to a http.Request
*/
type AdminServiceGetRoundDetailsParams struct {
/*RoundID*/
RoundID string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) WithTimeout(timeout time.Duration) *AdminServiceGetRoundDetailsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) WithContext(ctx context.Context) *AdminServiceGetRoundDetailsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) WithHTTPClient(client *http.Client) *AdminServiceGetRoundDetailsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithRoundID adds the roundID to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) WithRoundID(roundID string) *AdminServiceGetRoundDetailsParams {
o.SetRoundID(roundID)
return o
}
// SetRoundID adds the roundId to the admin service get round details params
func (o *AdminServiceGetRoundDetailsParams) SetRoundID(roundID string) {
o.RoundID = roundID
}
// WriteToRequest writes these params to a swagger request
func (o *AdminServiceGetRoundDetailsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param roundId
if err := r.SetPathParam("roundId", o.RoundID); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/admin/models"
)
// AdminServiceGetRoundDetailsReader is a Reader for the AdminServiceGetRoundDetails structure.
type AdminServiceGetRoundDetailsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *AdminServiceGetRoundDetailsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewAdminServiceGetRoundDetailsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewAdminServiceGetRoundDetailsDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewAdminServiceGetRoundDetailsOK creates a AdminServiceGetRoundDetailsOK with default headers values
func NewAdminServiceGetRoundDetailsOK() *AdminServiceGetRoundDetailsOK {
return &AdminServiceGetRoundDetailsOK{}
}
/*AdminServiceGetRoundDetailsOK handles this case with default header values.
A successful response.
*/
type AdminServiceGetRoundDetailsOK struct {
Payload *models.V1GetRoundDetailsResponse
}
func (o *AdminServiceGetRoundDetailsOK) Error() string {
return fmt.Sprintf("[GET /v1/admin/round/{roundId}][%d] adminServiceGetRoundDetailsOK %+v", 200, o.Payload)
}
func (o *AdminServiceGetRoundDetailsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1GetRoundDetailsResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewAdminServiceGetRoundDetailsDefault creates a AdminServiceGetRoundDetailsDefault with default headers values
func NewAdminServiceGetRoundDetailsDefault(code int) *AdminServiceGetRoundDetailsDefault {
return &AdminServiceGetRoundDetailsDefault{
_statusCode: code,
}
}
/*AdminServiceGetRoundDetailsDefault handles this case with default header values.
An unexpected error response.
*/
type AdminServiceGetRoundDetailsDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the admin service get round details default response
func (o *AdminServiceGetRoundDetailsDefault) Code() int {
return o._statusCode
}
func (o *AdminServiceGetRoundDetailsDefault) Error() string {
return fmt.Sprintf("[GET /v1/admin/round/{roundId}][%d] AdminService_GetRoundDetails default %+v", o._statusCode, o.Payload)
}
func (o *AdminServiceGetRoundDetailsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/admin/models"
)
// NewAdminServiceGetRoundsParams creates a new AdminServiceGetRoundsParams object
// with the default values initialized.
func NewAdminServiceGetRoundsParams() *AdminServiceGetRoundsParams {
var ()
return &AdminServiceGetRoundsParams{
timeout: cr.DefaultTimeout,
}
}
// NewAdminServiceGetRoundsParamsWithTimeout creates a new AdminServiceGetRoundsParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewAdminServiceGetRoundsParamsWithTimeout(timeout time.Duration) *AdminServiceGetRoundsParams {
var ()
return &AdminServiceGetRoundsParams{
timeout: timeout,
}
}
// NewAdminServiceGetRoundsParamsWithContext creates a new AdminServiceGetRoundsParams object
// with the default values initialized, and the ability to set a context for a request
func NewAdminServiceGetRoundsParamsWithContext(ctx context.Context) *AdminServiceGetRoundsParams {
var ()
return &AdminServiceGetRoundsParams{
Context: ctx,
}
}
// NewAdminServiceGetRoundsParamsWithHTTPClient creates a new AdminServiceGetRoundsParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewAdminServiceGetRoundsParamsWithHTTPClient(client *http.Client) *AdminServiceGetRoundsParams {
var ()
return &AdminServiceGetRoundsParams{
HTTPClient: client,
}
}
/*AdminServiceGetRoundsParams contains all the parameters to send to the API endpoint
for the admin service get rounds operation typically these are written to a http.Request
*/
type AdminServiceGetRoundsParams struct {
/*Body*/
Body *models.V1GetRoundsRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) WithTimeout(timeout time.Duration) *AdminServiceGetRoundsParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) WithContext(ctx context.Context) *AdminServiceGetRoundsParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) WithHTTPClient(client *http.Client) *AdminServiceGetRoundsParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) WithBody(body *models.V1GetRoundsRequest) *AdminServiceGetRoundsParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the admin service get rounds params
func (o *AdminServiceGetRoundsParams) SetBody(body *models.V1GetRoundsRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *AdminServiceGetRoundsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/admin/models"
)
// AdminServiceGetRoundsReader is a Reader for the AdminServiceGetRounds structure.
type AdminServiceGetRoundsReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *AdminServiceGetRoundsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewAdminServiceGetRoundsOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewAdminServiceGetRoundsDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewAdminServiceGetRoundsOK creates a AdminServiceGetRoundsOK with default headers values
func NewAdminServiceGetRoundsOK() *AdminServiceGetRoundsOK {
return &AdminServiceGetRoundsOK{}
}
/*AdminServiceGetRoundsOK handles this case with default header values.
A successful response.
*/
type AdminServiceGetRoundsOK struct {
Payload *models.V1GetRoundsResponse
}
func (o *AdminServiceGetRoundsOK) Error() string {
return fmt.Sprintf("[POST /v1/admin/rounds][%d] adminServiceGetRoundsOK %+v", 200, o.Payload)
}
func (o *AdminServiceGetRoundsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1GetRoundsResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewAdminServiceGetRoundsDefault creates a AdminServiceGetRoundsDefault with default headers values
func NewAdminServiceGetRoundsDefault(code int) *AdminServiceGetRoundsDefault {
return &AdminServiceGetRoundsDefault{
_statusCode: code,
}
}
/*AdminServiceGetRoundsDefault handles this case with default header values.
An unexpected error response.
*/
type AdminServiceGetRoundsDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the admin service get rounds default response
func (o *AdminServiceGetRoundsDefault) Code() int {
return o._statusCode
}
func (o *AdminServiceGetRoundsDefault) Error() string {
return fmt.Sprintf("[POST /v1/admin/rounds][%d] AdminService_GetRounds default %+v", o._statusCode, o.Payload)
}
func (o *AdminServiceGetRoundsDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,113 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewAdminServiceGetScheduledSweepParams creates a new AdminServiceGetScheduledSweepParams object
// with the default values initialized.
func NewAdminServiceGetScheduledSweepParams() *AdminServiceGetScheduledSweepParams {
return &AdminServiceGetScheduledSweepParams{
timeout: cr.DefaultTimeout,
}
}
// NewAdminServiceGetScheduledSweepParamsWithTimeout creates a new AdminServiceGetScheduledSweepParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewAdminServiceGetScheduledSweepParamsWithTimeout(timeout time.Duration) *AdminServiceGetScheduledSweepParams {
return &AdminServiceGetScheduledSweepParams{
timeout: timeout,
}
}
// NewAdminServiceGetScheduledSweepParamsWithContext creates a new AdminServiceGetScheduledSweepParams object
// with the default values initialized, and the ability to set a context for a request
func NewAdminServiceGetScheduledSweepParamsWithContext(ctx context.Context) *AdminServiceGetScheduledSweepParams {
return &AdminServiceGetScheduledSweepParams{
Context: ctx,
}
}
// NewAdminServiceGetScheduledSweepParamsWithHTTPClient creates a new AdminServiceGetScheduledSweepParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewAdminServiceGetScheduledSweepParamsWithHTTPClient(client *http.Client) *AdminServiceGetScheduledSweepParams {
return &AdminServiceGetScheduledSweepParams{
HTTPClient: client,
}
}
/*AdminServiceGetScheduledSweepParams contains all the parameters to send to the API endpoint
for the admin service get scheduled sweep operation typically these are written to a http.Request
*/
type AdminServiceGetScheduledSweepParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the admin service get scheduled sweep params
func (o *AdminServiceGetScheduledSweepParams) WithTimeout(timeout time.Duration) *AdminServiceGetScheduledSweepParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the admin service get scheduled sweep params
func (o *AdminServiceGetScheduledSweepParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the admin service get scheduled sweep params
func (o *AdminServiceGetScheduledSweepParams) WithContext(ctx context.Context) *AdminServiceGetScheduledSweepParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the admin service get scheduled sweep params
func (o *AdminServiceGetScheduledSweepParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the admin service get scheduled sweep params
func (o *AdminServiceGetScheduledSweepParams) WithHTTPClient(client *http.Client) *AdminServiceGetScheduledSweepParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the admin service get scheduled sweep params
func (o *AdminServiceGetScheduledSweepParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *AdminServiceGetScheduledSweepParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package admin_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/admin/models"
)
// AdminServiceGetScheduledSweepReader is a Reader for the AdminServiceGetScheduledSweep structure.
type AdminServiceGetScheduledSweepReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *AdminServiceGetScheduledSweepReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewAdminServiceGetScheduledSweepOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewAdminServiceGetScheduledSweepDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewAdminServiceGetScheduledSweepOK creates a AdminServiceGetScheduledSweepOK with default headers values
func NewAdminServiceGetScheduledSweepOK() *AdminServiceGetScheduledSweepOK {
return &AdminServiceGetScheduledSweepOK{}
}
/*AdminServiceGetScheduledSweepOK handles this case with default header values.
A successful response.
*/
type AdminServiceGetScheduledSweepOK struct {
Payload *models.V1GetScheduledSweepResponse
}
func (o *AdminServiceGetScheduledSweepOK) Error() string {
return fmt.Sprintf("[GET /v1/admin/sweeps][%d] adminServiceGetScheduledSweepOK %+v", 200, o.Payload)
}
func (o *AdminServiceGetScheduledSweepOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1GetScheduledSweepResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewAdminServiceGetScheduledSweepDefault creates a AdminServiceGetScheduledSweepDefault with default headers values
func NewAdminServiceGetScheduledSweepDefault(code int) *AdminServiceGetScheduledSweepDefault {
return &AdminServiceGetScheduledSweepDefault{
_statusCode: code,
}
}
/*AdminServiceGetScheduledSweepDefault handles this case with default header values.
An unexpected error response.
*/
type AdminServiceGetScheduledSweepDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the admin service get scheduled sweep default response
func (o *AdminServiceGetScheduledSweepDefault) Code() int {
return o._statusCode
}
func (o *AdminServiceGetScheduledSweepDefault) Error() string {
return fmt.Sprintf("[GET /v1/admin/sweeps][%d] AdminService_GetScheduledSweep default %+v", o._statusCode, o.Payload)
}
func (o *AdminServiceGetScheduledSweepDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,117 @@
// Code generated by go-swagger; DO NOT EDIT.
package arkadminrestclient
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
"github.com/ark-network/ark-sdk/rest/admin/arkadminrestclient/admin_service"
)
// Default ark v1 admin proto HTTP client.
var Default = NewHTTPClient(nil)
const (
// DefaultHost is the default Host
// found in Meta (info) section of spec file
DefaultHost string = "localhost"
// DefaultBasePath is the default BasePath
// found in Meta (info) section of spec file
DefaultBasePath string = "/"
)
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
var DefaultSchemes = []string{"http"}
// NewHTTPClient creates a new ark v1 admin proto HTTP client.
func NewHTTPClient(formats strfmt.Registry) *ArkV1AdminProto {
return NewHTTPClientWithConfig(formats, nil)
}
// NewHTTPClientWithConfig creates a new ark v1 admin proto HTTP client,
// using a customizable transport config.
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *ArkV1AdminProto {
// ensure nullable parameters have default
if cfg == nil {
cfg = DefaultTransportConfig()
}
// create transport and client
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
return New(transport, formats)
}
// New creates a new ark v1 admin proto client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *ArkV1AdminProto {
// ensure nullable parameters have default
if formats == nil {
formats = strfmt.Default
}
cli := new(ArkV1AdminProto)
cli.Transport = transport
cli.AdminService = admin_service.New(transport, formats)
return cli
}
// DefaultTransportConfig creates a TransportConfig with the
// default settings taken from the meta section of the spec file.
func DefaultTransportConfig() *TransportConfig {
return &TransportConfig{
Host: DefaultHost,
BasePath: DefaultBasePath,
Schemes: DefaultSchemes,
}
}
// TransportConfig contains the transport related info,
// found in the meta section of the spec file.
type TransportConfig struct {
Host string
BasePath string
Schemes []string
}
// WithHost overrides the default host,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
cfg.Host = host
return cfg
}
// WithBasePath overrides the default basePath,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
cfg.BasePath = basePath
return cfg
}
// WithSchemes overrides the default schemes,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
cfg.Schemes = schemes
return cfg
}
// ArkV1AdminProto is a client for ark v1 admin proto
type ArkV1AdminProto struct {
AdminService *admin_service.Client
Transport runtime.ClientTransport
}
// SetTransport changes the transport on the client and all its subresources
func (c *ArkV1AdminProto) SetTransport(transport runtime.ClientTransport) {
c.Transport = transport
c.AdminService.SetTransport(transport)
}

View File

@@ -0,0 +1,43 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// ProtobufAny protobuf any
// swagger:model protobufAny
type ProtobufAny struct {
// at type
AtType string `json:"@type,omitempty"`
}
// Validate validates this protobuf any
func (m *ProtobufAny) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *ProtobufAny) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *ProtobufAny) UnmarshalBinary(b []byte) error {
var res ProtobufAny
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,86 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// RPCStatus rpc status
// swagger:model rpcStatus
type RPCStatus struct {
// code
Code int32 `json:"code,omitempty"`
// details
Details []*ProtobufAny `json:"details"`
// message
Message string `json:"message,omitempty"`
}
// Validate validates this rpc status
func (m *RPCStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateDetails(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *RPCStatus) validateDetails(formats strfmt.Registry) error {
if swag.IsZero(m.Details) { // not required
return nil
}
for i := 0; i < len(m.Details); i++ {
if swag.IsZero(m.Details[i]) { // not required
continue
}
if m.Details[i] != nil {
if err := m.Details[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("details" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *RPCStatus) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *RPCStatus) UnmarshalBinary(b []byte) error {
var res RPCStatus
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,46 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1Balance v1 balance
// swagger:model v1Balance
type V1Balance struct {
// available
Available string `json:"available,omitempty"`
// locked
Locked string `json:"locked,omitempty"`
}
// Validate validates this v1 balance
func (m *V1Balance) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1Balance) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1Balance) UnmarshalBinary(b []byte) error {
var res V1Balance
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,96 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1GetBalanceResponse v1 get balance response
// swagger:model v1GetBalanceResponse
type V1GetBalanceResponse struct {
// connectors account
ConnectorsAccount *V1Balance `json:"connectorsAccount,omitempty"`
// main account
MainAccount *V1Balance `json:"mainAccount,omitempty"`
}
// Validate validates this v1 get balance response
func (m *V1GetBalanceResponse) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateConnectorsAccount(formats); err != nil {
res = append(res, err)
}
if err := m.validateMainAccount(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1GetBalanceResponse) validateConnectorsAccount(formats strfmt.Registry) error {
if swag.IsZero(m.ConnectorsAccount) { // not required
return nil
}
if m.ConnectorsAccount != nil {
if err := m.ConnectorsAccount.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("connectorsAccount")
}
return err
}
}
return nil
}
func (m *V1GetBalanceResponse) validateMainAccount(formats strfmt.Registry) error {
if swag.IsZero(m.MainAccount) { // not required
return nil
}
if m.MainAccount != nil {
if err := m.MainAccount.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("mainAccount")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1GetBalanceResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetBalanceResponse) UnmarshalBinary(b []byte) error {
var res V1GetBalanceResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,67 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1GetRoundDetailsResponse v1 get round details response
// swagger:model v1GetRoundDetailsResponse
type V1GetRoundDetailsResponse struct {
// exit addresses
ExitAddresses []string `json:"exitAddresses"`
// fees amount
FeesAmount string `json:"feesAmount,omitempty"`
// forfeited amount
ForfeitedAmount string `json:"forfeitedAmount,omitempty"`
// inputs vtxos
InputsVtxos []string `json:"inputsVtxos"`
// outputs vtxos
OutputsVtxos []string `json:"outputsVtxos"`
// round Id
RoundID string `json:"roundId,omitempty"`
// total exit amount
TotalExitAmount string `json:"totalExitAmount,omitempty"`
// total vtxos amount
TotalVtxosAmount string `json:"totalVtxosAmount,omitempty"`
// txid
Txid string `json:"txid,omitempty"`
}
// Validate validates this v1 get round details response
func (m *V1GetRoundDetailsResponse) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1GetRoundDetailsResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetRoundDetailsResponse) UnmarshalBinary(b []byte) error {
var res V1GetRoundDetailsResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,46 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1GetRoundsRequest v1 get rounds request
// swagger:model v1GetRoundsRequest
type V1GetRoundsRequest struct {
// after
After string `json:"after,omitempty"`
// before
Before string `json:"before,omitempty"`
}
// Validate validates this v1 get rounds request
func (m *V1GetRoundsRequest) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1GetRoundsRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetRoundsRequest) UnmarshalBinary(b []byte) error {
var res V1GetRoundsRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,43 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1GetRoundsResponse v1 get rounds response
// swagger:model v1GetRoundsResponse
type V1GetRoundsResponse struct {
// rounds
Rounds []string `json:"rounds"`
}
// Validate validates this v1 get rounds response
func (m *V1GetRoundsResponse) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1GetRoundsResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetRoundsResponse) UnmarshalBinary(b []byte) error {
var res V1GetRoundsResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,80 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1GetScheduledSweepResponse v1 get scheduled sweep response
// swagger:model v1GetScheduledSweepResponse
type V1GetScheduledSweepResponse struct {
// sweeps
Sweeps []*V1ScheduledSweep `json:"sweeps"`
}
// Validate validates this v1 get scheduled sweep response
func (m *V1GetScheduledSweepResponse) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateSweeps(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1GetScheduledSweepResponse) validateSweeps(formats strfmt.Registry) error {
if swag.IsZero(m.Sweeps) { // not required
return nil
}
for i := 0; i < len(m.Sweeps); i++ {
if swag.IsZero(m.Sweeps[i]) { // not required
continue
}
if m.Sweeps[i] != nil {
if err := m.Sweeps[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("sweeps" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1GetScheduledSweepResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetScheduledSweepResponse) UnmarshalBinary(b []byte) error {
var res V1GetScheduledSweepResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,83 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1ScheduledSweep v1 scheduled sweep
// swagger:model v1ScheduledSweep
type V1ScheduledSweep struct {
// outputs
Outputs []*V1SweepableOutput `json:"outputs"`
// round Id
RoundID string `json:"roundId,omitempty"`
}
// Validate validates this v1 scheduled sweep
func (m *V1ScheduledSweep) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateOutputs(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1ScheduledSweep) validateOutputs(formats strfmt.Registry) error {
if swag.IsZero(m.Outputs) { // not required
return nil
}
for i := 0; i < len(m.Outputs); i++ {
if swag.IsZero(m.Outputs[i]) { // not required
continue
}
if m.Outputs[i] != nil {
if err := m.Outputs[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("outputs" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1ScheduledSweep) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1ScheduledSweep) UnmarshalBinary(b []byte) error {
var res V1ScheduledSweep
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,52 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1SweepableOutput v1 sweepable output
// swagger:model v1SweepableOutput
type V1SweepableOutput struct {
// amount
Amount string `json:"amount,omitempty"`
// scheduled at
ScheduledAt string `json:"scheduledAt,omitempty"`
// txid
Txid string `json:"txid,omitempty"`
// vout
Vout int64 `json:"vout,omitempty"`
}
// Validate validates this v1 sweepable output
func (m *V1SweepableOutput) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1SweepableOutput) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1SweepableOutput) UnmarshalBinary(b []byte) error {
var res V1SweepableOutput
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// NewArkServiceClaimPaymentParams creates a new ArkServiceClaimPaymentParams object
// with the default values initialized.
func NewArkServiceClaimPaymentParams() *ArkServiceClaimPaymentParams {
var ()
return &ArkServiceClaimPaymentParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceClaimPaymentParamsWithTimeout creates a new ArkServiceClaimPaymentParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceClaimPaymentParamsWithTimeout(timeout time.Duration) *ArkServiceClaimPaymentParams {
var ()
return &ArkServiceClaimPaymentParams{
timeout: timeout,
}
}
// NewArkServiceClaimPaymentParamsWithContext creates a new ArkServiceClaimPaymentParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceClaimPaymentParamsWithContext(ctx context.Context) *ArkServiceClaimPaymentParams {
var ()
return &ArkServiceClaimPaymentParams{
Context: ctx,
}
}
// NewArkServiceClaimPaymentParamsWithHTTPClient creates a new ArkServiceClaimPaymentParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceClaimPaymentParamsWithHTTPClient(client *http.Client) *ArkServiceClaimPaymentParams {
var ()
return &ArkServiceClaimPaymentParams{
HTTPClient: client,
}
}
/*ArkServiceClaimPaymentParams contains all the parameters to send to the API endpoint
for the ark service claim payment operation typically these are written to a http.Request
*/
type ArkServiceClaimPaymentParams struct {
/*Body*/
Body *models.V1ClaimPaymentRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) WithTimeout(timeout time.Duration) *ArkServiceClaimPaymentParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) WithContext(ctx context.Context) *ArkServiceClaimPaymentParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) WithHTTPClient(client *http.Client) *ArkServiceClaimPaymentParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) WithBody(body *models.V1ClaimPaymentRequest) *ArkServiceClaimPaymentParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the ark service claim payment params
func (o *ArkServiceClaimPaymentParams) SetBody(body *models.V1ClaimPaymentRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceClaimPaymentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,110 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceClaimPaymentReader is a Reader for the ArkServiceClaimPayment structure.
type ArkServiceClaimPaymentReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceClaimPaymentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceClaimPaymentOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceClaimPaymentDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceClaimPaymentOK creates a ArkServiceClaimPaymentOK with default headers values
func NewArkServiceClaimPaymentOK() *ArkServiceClaimPaymentOK {
return &ArkServiceClaimPaymentOK{}
}
/*ArkServiceClaimPaymentOK handles this case with default header values.
A successful response.
*/
type ArkServiceClaimPaymentOK struct {
Payload models.V1ClaimPaymentResponse
}
func (o *ArkServiceClaimPaymentOK) Error() string {
return fmt.Sprintf("[POST /v1/payment/claim][%d] arkServiceClaimPaymentOK %+v", 200, o.Payload)
}
func (o *ArkServiceClaimPaymentOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceClaimPaymentDefault creates a ArkServiceClaimPaymentDefault with default headers values
func NewArkServiceClaimPaymentDefault(code int) *ArkServiceClaimPaymentDefault {
return &ArkServiceClaimPaymentDefault{
_statusCode: code,
}
}
/*ArkServiceClaimPaymentDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceClaimPaymentDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service claim payment default response
func (o *ArkServiceClaimPaymentDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceClaimPaymentDefault) Error() string {
return fmt.Sprintf("[POST /v1/payment/claim][%d] ArkService_ClaimPayment default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceClaimPaymentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,338 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
)
// New creates a new ark service API client.
func New(transport runtime.ClientTransport, formats strfmt.Registry) *Client {
return &Client{transport: transport, formats: formats}
}
/*
Client for ark service API
*/
type Client struct {
transport runtime.ClientTransport
formats strfmt.Registry
}
/*
ArkServiceClaimPayment ark service claim payment API
*/
func (a *Client) ArkServiceClaimPayment(params *ArkServiceClaimPaymentParams) (*ArkServiceClaimPaymentOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceClaimPaymentParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_ClaimPayment",
Method: "POST",
PathPattern: "/v1/payment/claim",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceClaimPaymentReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceClaimPaymentOK), nil
}
/*
ArkServiceFinalizePayment ark service finalize payment API
*/
func (a *Client) ArkServiceFinalizePayment(params *ArkServiceFinalizePaymentParams) (*ArkServiceFinalizePaymentOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceFinalizePaymentParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_FinalizePayment",
Method: "POST",
PathPattern: "/v1/payment/finalize",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceFinalizePaymentReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceFinalizePaymentOK), nil
}
/*
ArkServiceGetEventStream ark service get event stream API
*/
func (a *Client) ArkServiceGetEventStream(params *ArkServiceGetEventStreamParams) (*ArkServiceGetEventStreamOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceGetEventStreamParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_GetEventStream",
Method: "GET",
PathPattern: "/v1/events",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceGetEventStreamReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceGetEventStreamOK), nil
}
/*
ArkServiceGetInfo ark service get info API
*/
func (a *Client) ArkServiceGetInfo(params *ArkServiceGetInfoParams) (*ArkServiceGetInfoOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceGetInfoParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_GetInfo",
Method: "GET",
PathPattern: "/v1/info",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceGetInfoReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceGetInfoOK), nil
}
/*
ArkServiceGetRound ts o d o b t c sign tree rpc
*/
func (a *Client) ArkServiceGetRound(params *ArkServiceGetRoundParams) (*ArkServiceGetRoundOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceGetRoundParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_GetRound",
Method: "GET",
PathPattern: "/v1/round/{txid}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceGetRoundReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceGetRoundOK), nil
}
/*
ArkServiceGetRoundByID ark service get round by Id API
*/
func (a *Client) ArkServiceGetRoundByID(params *ArkServiceGetRoundByIDParams) (*ArkServiceGetRoundByIDOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceGetRoundByIDParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_GetRoundById",
Method: "GET",
PathPattern: "/v1/round/id/{id}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceGetRoundByIDReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceGetRoundByIDOK), nil
}
/*
ArkServiceListVtxos ark service list vtxos API
*/
func (a *Client) ArkServiceListVtxos(params *ArkServiceListVtxosParams) (*ArkServiceListVtxosOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceListVtxosParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_ListVtxos",
Method: "GET",
PathPattern: "/v1/vtxos/{address}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceListVtxosReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceListVtxosOK), nil
}
/*
ArkServiceOnboard ark service onboard API
*/
func (a *Client) ArkServiceOnboard(params *ArkServiceOnboardParams) (*ArkServiceOnboardOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceOnboardParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_Onboard",
Method: "POST",
PathPattern: "/v1/onboard",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceOnboardReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceOnboardOK), nil
}
/*
ArkServicePing ark service ping API
*/
func (a *Client) ArkServicePing(params *ArkServicePingParams) (*ArkServicePingOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServicePingParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_Ping",
Method: "GET",
PathPattern: "/v1/ping/{paymentId}",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServicePingReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServicePingOK), nil
}
/*
ArkServiceRegisterPayment ark service register payment API
*/
func (a *Client) ArkServiceRegisterPayment(params *ArkServiceRegisterPaymentParams) (*ArkServiceRegisterPaymentOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceRegisterPaymentParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_RegisterPayment",
Method: "POST",
PathPattern: "/v1/payment/register",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceRegisterPaymentReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceRegisterPaymentOK), nil
}
/*
ArkServiceTrustedOnboarding ark service trusted onboarding API
*/
func (a *Client) ArkServiceTrustedOnboarding(params *ArkServiceTrustedOnboardingParams) (*ArkServiceTrustedOnboardingOK, error) {
// TODO: Validate the params before sending
if params == nil {
params = NewArkServiceTrustedOnboardingParams()
}
result, err := a.transport.Submit(&runtime.ClientOperation{
ID: "ArkService_TrustedOnboarding",
Method: "POST",
PathPattern: "/v1/onboard/address",
ProducesMediaTypes: []string{"application/json"},
ConsumesMediaTypes: []string{"application/json"},
Schemes: []string{"http"},
Params: params,
Reader: &ArkServiceTrustedOnboardingReader{formats: a.formats},
Context: params.Context,
Client: params.HTTPClient,
})
if err != nil {
return nil, err
}
return result.(*ArkServiceTrustedOnboardingOK), nil
}
// SetTransport changes the transport on the client
func (a *Client) SetTransport(transport runtime.ClientTransport) {
a.transport = transport
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// NewArkServiceFinalizePaymentParams creates a new ArkServiceFinalizePaymentParams object
// with the default values initialized.
func NewArkServiceFinalizePaymentParams() *ArkServiceFinalizePaymentParams {
var ()
return &ArkServiceFinalizePaymentParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceFinalizePaymentParamsWithTimeout creates a new ArkServiceFinalizePaymentParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceFinalizePaymentParamsWithTimeout(timeout time.Duration) *ArkServiceFinalizePaymentParams {
var ()
return &ArkServiceFinalizePaymentParams{
timeout: timeout,
}
}
// NewArkServiceFinalizePaymentParamsWithContext creates a new ArkServiceFinalizePaymentParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceFinalizePaymentParamsWithContext(ctx context.Context) *ArkServiceFinalizePaymentParams {
var ()
return &ArkServiceFinalizePaymentParams{
Context: ctx,
}
}
// NewArkServiceFinalizePaymentParamsWithHTTPClient creates a new ArkServiceFinalizePaymentParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceFinalizePaymentParamsWithHTTPClient(client *http.Client) *ArkServiceFinalizePaymentParams {
var ()
return &ArkServiceFinalizePaymentParams{
HTTPClient: client,
}
}
/*ArkServiceFinalizePaymentParams contains all the parameters to send to the API endpoint
for the ark service finalize payment operation typically these are written to a http.Request
*/
type ArkServiceFinalizePaymentParams struct {
/*Body*/
Body *models.V1FinalizePaymentRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) WithTimeout(timeout time.Duration) *ArkServiceFinalizePaymentParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) WithContext(ctx context.Context) *ArkServiceFinalizePaymentParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) WithHTTPClient(client *http.Client) *ArkServiceFinalizePaymentParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) WithBody(body *models.V1FinalizePaymentRequest) *ArkServiceFinalizePaymentParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the ark service finalize payment params
func (o *ArkServiceFinalizePaymentParams) SetBody(body *models.V1FinalizePaymentRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceFinalizePaymentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,110 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceFinalizePaymentReader is a Reader for the ArkServiceFinalizePayment structure.
type ArkServiceFinalizePaymentReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceFinalizePaymentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceFinalizePaymentOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceFinalizePaymentDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceFinalizePaymentOK creates a ArkServiceFinalizePaymentOK with default headers values
func NewArkServiceFinalizePaymentOK() *ArkServiceFinalizePaymentOK {
return &ArkServiceFinalizePaymentOK{}
}
/*ArkServiceFinalizePaymentOK handles this case with default header values.
A successful response.
*/
type ArkServiceFinalizePaymentOK struct {
Payload models.V1FinalizePaymentResponse
}
func (o *ArkServiceFinalizePaymentOK) Error() string {
return fmt.Sprintf("[POST /v1/payment/finalize][%d] arkServiceFinalizePaymentOK %+v", 200, o.Payload)
}
func (o *ArkServiceFinalizePaymentOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceFinalizePaymentDefault creates a ArkServiceFinalizePaymentDefault with default headers values
func NewArkServiceFinalizePaymentDefault(code int) *ArkServiceFinalizePaymentDefault {
return &ArkServiceFinalizePaymentDefault{
_statusCode: code,
}
}
/*ArkServiceFinalizePaymentDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceFinalizePaymentDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service finalize payment default response
func (o *ArkServiceFinalizePaymentDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceFinalizePaymentDefault) Error() string {
return fmt.Sprintf("[POST /v1/payment/finalize][%d] ArkService_FinalizePayment default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceFinalizePaymentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,113 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewArkServiceGetEventStreamParams creates a new ArkServiceGetEventStreamParams object
// with the default values initialized.
func NewArkServiceGetEventStreamParams() *ArkServiceGetEventStreamParams {
return &ArkServiceGetEventStreamParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceGetEventStreamParamsWithTimeout creates a new ArkServiceGetEventStreamParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceGetEventStreamParamsWithTimeout(timeout time.Duration) *ArkServiceGetEventStreamParams {
return &ArkServiceGetEventStreamParams{
timeout: timeout,
}
}
// NewArkServiceGetEventStreamParamsWithContext creates a new ArkServiceGetEventStreamParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceGetEventStreamParamsWithContext(ctx context.Context) *ArkServiceGetEventStreamParams {
return &ArkServiceGetEventStreamParams{
Context: ctx,
}
}
// NewArkServiceGetEventStreamParamsWithHTTPClient creates a new ArkServiceGetEventStreamParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceGetEventStreamParamsWithHTTPClient(client *http.Client) *ArkServiceGetEventStreamParams {
return &ArkServiceGetEventStreamParams{
HTTPClient: client,
}
}
/*ArkServiceGetEventStreamParams contains all the parameters to send to the API endpoint
for the ark service get event stream operation typically these are written to a http.Request
*/
type ArkServiceGetEventStreamParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service get event stream params
func (o *ArkServiceGetEventStreamParams) WithTimeout(timeout time.Duration) *ArkServiceGetEventStreamParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service get event stream params
func (o *ArkServiceGetEventStreamParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service get event stream params
func (o *ArkServiceGetEventStreamParams) WithContext(ctx context.Context) *ArkServiceGetEventStreamParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service get event stream params
func (o *ArkServiceGetEventStreamParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service get event stream params
func (o *ArkServiceGetEventStreamParams) WithHTTPClient(client *http.Client) *ArkServiceGetEventStreamParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service get event stream params
func (o *ArkServiceGetEventStreamParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceGetEventStreamParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,198 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
"github.com/go-openapi/swag"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceGetEventStreamReader is a Reader for the ArkServiceGetEventStream structure.
type ArkServiceGetEventStreamReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceGetEventStreamReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceGetEventStreamOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceGetEventStreamDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceGetEventStreamOK creates a ArkServiceGetEventStreamOK with default headers values
func NewArkServiceGetEventStreamOK() *ArkServiceGetEventStreamOK {
return &ArkServiceGetEventStreamOK{}
}
/*ArkServiceGetEventStreamOK handles this case with default header values.
A successful response.(streaming responses)
*/
type ArkServiceGetEventStreamOK struct {
Payload *ArkServiceGetEventStreamOKBody
}
func (o *ArkServiceGetEventStreamOK) Error() string {
return fmt.Sprintf("[GET /v1/events][%d] arkServiceGetEventStreamOK %+v", 200, o.Payload)
}
func (o *ArkServiceGetEventStreamOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(ArkServiceGetEventStreamOKBody)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceGetEventStreamDefault creates a ArkServiceGetEventStreamDefault with default headers values
func NewArkServiceGetEventStreamDefault(code int) *ArkServiceGetEventStreamDefault {
return &ArkServiceGetEventStreamDefault{
_statusCode: code,
}
}
/*ArkServiceGetEventStreamDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceGetEventStreamDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service get event stream default response
func (o *ArkServiceGetEventStreamDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceGetEventStreamDefault) Error() string {
return fmt.Sprintf("[GET /v1/events][%d] ArkService_GetEventStream default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceGetEventStreamDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
/*ArkServiceGetEventStreamOKBody Stream result of v1GetEventStreamResponse
swagger:model ArkServiceGetEventStreamOKBody
*/
type ArkServiceGetEventStreamOKBody struct {
// error
Error *models.RPCStatus `json:"error,omitempty"`
// result
Result *models.V1GetEventStreamResponse `json:"result,omitempty"`
}
// Validate validates this ark service get event stream o k body
func (o *ArkServiceGetEventStreamOKBody) Validate(formats strfmt.Registry) error {
var res []error
if err := o.validateError(formats); err != nil {
res = append(res, err)
}
if err := o.validateResult(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (o *ArkServiceGetEventStreamOKBody) validateError(formats strfmt.Registry) error {
if swag.IsZero(o.Error) { // not required
return nil
}
if o.Error != nil {
if err := o.Error.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("arkServiceGetEventStreamOK" + "." + "error")
}
return err
}
}
return nil
}
func (o *ArkServiceGetEventStreamOKBody) validateResult(formats strfmt.Registry) error {
if swag.IsZero(o.Result) { // not required
return nil
}
if o.Result != nil {
if err := o.Result.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("arkServiceGetEventStreamOK" + "." + "result")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (o *ArkServiceGetEventStreamOKBody) MarshalBinary() ([]byte, error) {
if o == nil {
return nil, nil
}
return swag.WriteJSON(o)
}
// UnmarshalBinary interface implementation
func (o *ArkServiceGetEventStreamOKBody) UnmarshalBinary(b []byte) error {
var res ArkServiceGetEventStreamOKBody
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*o = res
return nil
}

View File

@@ -0,0 +1,113 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewArkServiceGetInfoParams creates a new ArkServiceGetInfoParams object
// with the default values initialized.
func NewArkServiceGetInfoParams() *ArkServiceGetInfoParams {
return &ArkServiceGetInfoParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceGetInfoParamsWithTimeout creates a new ArkServiceGetInfoParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceGetInfoParamsWithTimeout(timeout time.Duration) *ArkServiceGetInfoParams {
return &ArkServiceGetInfoParams{
timeout: timeout,
}
}
// NewArkServiceGetInfoParamsWithContext creates a new ArkServiceGetInfoParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceGetInfoParamsWithContext(ctx context.Context) *ArkServiceGetInfoParams {
return &ArkServiceGetInfoParams{
Context: ctx,
}
}
// NewArkServiceGetInfoParamsWithHTTPClient creates a new ArkServiceGetInfoParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceGetInfoParamsWithHTTPClient(client *http.Client) *ArkServiceGetInfoParams {
return &ArkServiceGetInfoParams{
HTTPClient: client,
}
}
/*ArkServiceGetInfoParams contains all the parameters to send to the API endpoint
for the ark service get info operation typically these are written to a http.Request
*/
type ArkServiceGetInfoParams struct {
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service get info params
func (o *ArkServiceGetInfoParams) WithTimeout(timeout time.Duration) *ArkServiceGetInfoParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service get info params
func (o *ArkServiceGetInfoParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service get info params
func (o *ArkServiceGetInfoParams) WithContext(ctx context.Context) *ArkServiceGetInfoParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service get info params
func (o *ArkServiceGetInfoParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service get info params
func (o *ArkServiceGetInfoParams) WithHTTPClient(client *http.Client) *ArkServiceGetInfoParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service get info params
func (o *ArkServiceGetInfoParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceGetInfoParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceGetInfoReader is a Reader for the ArkServiceGetInfo structure.
type ArkServiceGetInfoReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceGetInfoReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceGetInfoOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceGetInfoDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceGetInfoOK creates a ArkServiceGetInfoOK with default headers values
func NewArkServiceGetInfoOK() *ArkServiceGetInfoOK {
return &ArkServiceGetInfoOK{}
}
/*ArkServiceGetInfoOK handles this case with default header values.
A successful response.
*/
type ArkServiceGetInfoOK struct {
Payload *models.V1GetInfoResponse
}
func (o *ArkServiceGetInfoOK) Error() string {
return fmt.Sprintf("[GET /v1/info][%d] arkServiceGetInfoOK %+v", 200, o.Payload)
}
func (o *ArkServiceGetInfoOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1GetInfoResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceGetInfoDefault creates a ArkServiceGetInfoDefault with default headers values
func NewArkServiceGetInfoDefault(code int) *ArkServiceGetInfoDefault {
return &ArkServiceGetInfoDefault{
_statusCode: code,
}
}
/*ArkServiceGetInfoDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceGetInfoDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service get info default response
func (o *ArkServiceGetInfoDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceGetInfoDefault) Error() string {
return fmt.Sprintf("[GET /v1/info][%d] ArkService_GetInfo default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceGetInfoDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewArkServiceGetRoundByIDParams creates a new ArkServiceGetRoundByIDParams object
// with the default values initialized.
func NewArkServiceGetRoundByIDParams() *ArkServiceGetRoundByIDParams {
var ()
return &ArkServiceGetRoundByIDParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceGetRoundByIDParamsWithTimeout creates a new ArkServiceGetRoundByIDParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceGetRoundByIDParamsWithTimeout(timeout time.Duration) *ArkServiceGetRoundByIDParams {
var ()
return &ArkServiceGetRoundByIDParams{
timeout: timeout,
}
}
// NewArkServiceGetRoundByIDParamsWithContext creates a new ArkServiceGetRoundByIDParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceGetRoundByIDParamsWithContext(ctx context.Context) *ArkServiceGetRoundByIDParams {
var ()
return &ArkServiceGetRoundByIDParams{
Context: ctx,
}
}
// NewArkServiceGetRoundByIDParamsWithHTTPClient creates a new ArkServiceGetRoundByIDParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceGetRoundByIDParamsWithHTTPClient(client *http.Client) *ArkServiceGetRoundByIDParams {
var ()
return &ArkServiceGetRoundByIDParams{
HTTPClient: client,
}
}
/*ArkServiceGetRoundByIDParams contains all the parameters to send to the API endpoint
for the ark service get round by Id operation typically these are written to a http.Request
*/
type ArkServiceGetRoundByIDParams struct {
/*ID*/
ID string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) WithTimeout(timeout time.Duration) *ArkServiceGetRoundByIDParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) WithContext(ctx context.Context) *ArkServiceGetRoundByIDParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) WithHTTPClient(client *http.Client) *ArkServiceGetRoundByIDParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithID adds the id to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) WithID(id string) *ArkServiceGetRoundByIDParams {
o.SetID(id)
return o
}
// SetID adds the id to the ark service get round by Id params
func (o *ArkServiceGetRoundByIDParams) SetID(id string) {
o.ID = id
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceGetRoundByIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param id
if err := r.SetPathParam("id", o.ID); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceGetRoundByIDReader is a Reader for the ArkServiceGetRoundByID structure.
type ArkServiceGetRoundByIDReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceGetRoundByIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceGetRoundByIDOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceGetRoundByIDDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceGetRoundByIDOK creates a ArkServiceGetRoundByIDOK with default headers values
func NewArkServiceGetRoundByIDOK() *ArkServiceGetRoundByIDOK {
return &ArkServiceGetRoundByIDOK{}
}
/*ArkServiceGetRoundByIDOK handles this case with default header values.
A successful response.
*/
type ArkServiceGetRoundByIDOK struct {
Payload *models.V1GetRoundByIDResponse
}
func (o *ArkServiceGetRoundByIDOK) Error() string {
return fmt.Sprintf("[GET /v1/round/id/{id}][%d] arkServiceGetRoundByIdOK %+v", 200, o.Payload)
}
func (o *ArkServiceGetRoundByIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1GetRoundByIDResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceGetRoundByIDDefault creates a ArkServiceGetRoundByIDDefault with default headers values
func NewArkServiceGetRoundByIDDefault(code int) *ArkServiceGetRoundByIDDefault {
return &ArkServiceGetRoundByIDDefault{
_statusCode: code,
}
}
/*ArkServiceGetRoundByIDDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceGetRoundByIDDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service get round by Id default response
func (o *ArkServiceGetRoundByIDDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceGetRoundByIDDefault) Error() string {
return fmt.Sprintf("[GET /v1/round/id/{id}][%d] ArkService_GetRoundById default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceGetRoundByIDDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewArkServiceGetRoundParams creates a new ArkServiceGetRoundParams object
// with the default values initialized.
func NewArkServiceGetRoundParams() *ArkServiceGetRoundParams {
var ()
return &ArkServiceGetRoundParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceGetRoundParamsWithTimeout creates a new ArkServiceGetRoundParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceGetRoundParamsWithTimeout(timeout time.Duration) *ArkServiceGetRoundParams {
var ()
return &ArkServiceGetRoundParams{
timeout: timeout,
}
}
// NewArkServiceGetRoundParamsWithContext creates a new ArkServiceGetRoundParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceGetRoundParamsWithContext(ctx context.Context) *ArkServiceGetRoundParams {
var ()
return &ArkServiceGetRoundParams{
Context: ctx,
}
}
// NewArkServiceGetRoundParamsWithHTTPClient creates a new ArkServiceGetRoundParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceGetRoundParamsWithHTTPClient(client *http.Client) *ArkServiceGetRoundParams {
var ()
return &ArkServiceGetRoundParams{
HTTPClient: client,
}
}
/*ArkServiceGetRoundParams contains all the parameters to send to the API endpoint
for the ark service get round operation typically these are written to a http.Request
*/
type ArkServiceGetRoundParams struct {
/*Txid*/
Txid string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service get round params
func (o *ArkServiceGetRoundParams) WithTimeout(timeout time.Duration) *ArkServiceGetRoundParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service get round params
func (o *ArkServiceGetRoundParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service get round params
func (o *ArkServiceGetRoundParams) WithContext(ctx context.Context) *ArkServiceGetRoundParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service get round params
func (o *ArkServiceGetRoundParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service get round params
func (o *ArkServiceGetRoundParams) WithHTTPClient(client *http.Client) *ArkServiceGetRoundParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service get round params
func (o *ArkServiceGetRoundParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithTxid adds the txid to the ark service get round params
func (o *ArkServiceGetRoundParams) WithTxid(txid string) *ArkServiceGetRoundParams {
o.SetTxid(txid)
return o
}
// SetTxid adds the txid to the ark service get round params
func (o *ArkServiceGetRoundParams) SetTxid(txid string) {
o.Txid = txid
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceGetRoundParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param txid
if err := r.SetPathParam("txid", o.Txid); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceGetRoundReader is a Reader for the ArkServiceGetRound structure.
type ArkServiceGetRoundReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceGetRoundReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceGetRoundOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceGetRoundDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceGetRoundOK creates a ArkServiceGetRoundOK with default headers values
func NewArkServiceGetRoundOK() *ArkServiceGetRoundOK {
return &ArkServiceGetRoundOK{}
}
/*ArkServiceGetRoundOK handles this case with default header values.
A successful response.
*/
type ArkServiceGetRoundOK struct {
Payload *models.V1GetRoundResponse
}
func (o *ArkServiceGetRoundOK) Error() string {
return fmt.Sprintf("[GET /v1/round/{txid}][%d] arkServiceGetRoundOK %+v", 200, o.Payload)
}
func (o *ArkServiceGetRoundOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1GetRoundResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceGetRoundDefault creates a ArkServiceGetRoundDefault with default headers values
func NewArkServiceGetRoundDefault(code int) *ArkServiceGetRoundDefault {
return &ArkServiceGetRoundDefault{
_statusCode: code,
}
}
/*ArkServiceGetRoundDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceGetRoundDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service get round default response
func (o *ArkServiceGetRoundDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceGetRoundDefault) Error() string {
return fmt.Sprintf("[GET /v1/round/{txid}][%d] ArkService_GetRound default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceGetRoundDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewArkServiceListVtxosParams creates a new ArkServiceListVtxosParams object
// with the default values initialized.
func NewArkServiceListVtxosParams() *ArkServiceListVtxosParams {
var ()
return &ArkServiceListVtxosParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceListVtxosParamsWithTimeout creates a new ArkServiceListVtxosParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceListVtxosParamsWithTimeout(timeout time.Duration) *ArkServiceListVtxosParams {
var ()
return &ArkServiceListVtxosParams{
timeout: timeout,
}
}
// NewArkServiceListVtxosParamsWithContext creates a new ArkServiceListVtxosParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceListVtxosParamsWithContext(ctx context.Context) *ArkServiceListVtxosParams {
var ()
return &ArkServiceListVtxosParams{
Context: ctx,
}
}
// NewArkServiceListVtxosParamsWithHTTPClient creates a new ArkServiceListVtxosParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceListVtxosParamsWithHTTPClient(client *http.Client) *ArkServiceListVtxosParams {
var ()
return &ArkServiceListVtxosParams{
HTTPClient: client,
}
}
/*ArkServiceListVtxosParams contains all the parameters to send to the API endpoint
for the ark service list vtxos operation typically these are written to a http.Request
*/
type ArkServiceListVtxosParams struct {
/*Address*/
Address string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) WithTimeout(timeout time.Duration) *ArkServiceListVtxosParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) WithContext(ctx context.Context) *ArkServiceListVtxosParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) WithHTTPClient(client *http.Client) *ArkServiceListVtxosParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithAddress adds the address to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) WithAddress(address string) *ArkServiceListVtxosParams {
o.SetAddress(address)
return o
}
// SetAddress adds the address to the ark service list vtxos params
func (o *ArkServiceListVtxosParams) SetAddress(address string) {
o.Address = address
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceListVtxosParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param address
if err := r.SetPathParam("address", o.Address); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceListVtxosReader is a Reader for the ArkServiceListVtxos structure.
type ArkServiceListVtxosReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceListVtxosReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceListVtxosOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceListVtxosDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceListVtxosOK creates a ArkServiceListVtxosOK with default headers values
func NewArkServiceListVtxosOK() *ArkServiceListVtxosOK {
return &ArkServiceListVtxosOK{}
}
/*ArkServiceListVtxosOK handles this case with default header values.
A successful response.
*/
type ArkServiceListVtxosOK struct {
Payload *models.V1ListVtxosResponse
}
func (o *ArkServiceListVtxosOK) Error() string {
return fmt.Sprintf("[GET /v1/vtxos/{address}][%d] arkServiceListVtxosOK %+v", 200, o.Payload)
}
func (o *ArkServiceListVtxosOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1ListVtxosResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceListVtxosDefault creates a ArkServiceListVtxosDefault with default headers values
func NewArkServiceListVtxosDefault(code int) *ArkServiceListVtxosDefault {
return &ArkServiceListVtxosDefault{
_statusCode: code,
}
}
/*ArkServiceListVtxosDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceListVtxosDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service list vtxos default response
func (o *ArkServiceListVtxosDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceListVtxosDefault) Error() string {
return fmt.Sprintf("[GET /v1/vtxos/{address}][%d] ArkService_ListVtxos default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceListVtxosDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// NewArkServiceOnboardParams creates a new ArkServiceOnboardParams object
// with the default values initialized.
func NewArkServiceOnboardParams() *ArkServiceOnboardParams {
var ()
return &ArkServiceOnboardParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceOnboardParamsWithTimeout creates a new ArkServiceOnboardParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceOnboardParamsWithTimeout(timeout time.Duration) *ArkServiceOnboardParams {
var ()
return &ArkServiceOnboardParams{
timeout: timeout,
}
}
// NewArkServiceOnboardParamsWithContext creates a new ArkServiceOnboardParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceOnboardParamsWithContext(ctx context.Context) *ArkServiceOnboardParams {
var ()
return &ArkServiceOnboardParams{
Context: ctx,
}
}
// NewArkServiceOnboardParamsWithHTTPClient creates a new ArkServiceOnboardParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceOnboardParamsWithHTTPClient(client *http.Client) *ArkServiceOnboardParams {
var ()
return &ArkServiceOnboardParams{
HTTPClient: client,
}
}
/*ArkServiceOnboardParams contains all the parameters to send to the API endpoint
for the ark service onboard operation typically these are written to a http.Request
*/
type ArkServiceOnboardParams struct {
/*Body*/
Body *models.V1OnboardRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service onboard params
func (o *ArkServiceOnboardParams) WithTimeout(timeout time.Duration) *ArkServiceOnboardParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service onboard params
func (o *ArkServiceOnboardParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service onboard params
func (o *ArkServiceOnboardParams) WithContext(ctx context.Context) *ArkServiceOnboardParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service onboard params
func (o *ArkServiceOnboardParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service onboard params
func (o *ArkServiceOnboardParams) WithHTTPClient(client *http.Client) *ArkServiceOnboardParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service onboard params
func (o *ArkServiceOnboardParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the ark service onboard params
func (o *ArkServiceOnboardParams) WithBody(body *models.V1OnboardRequest) *ArkServiceOnboardParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the ark service onboard params
func (o *ArkServiceOnboardParams) SetBody(body *models.V1OnboardRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceOnboardParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,110 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceOnboardReader is a Reader for the ArkServiceOnboard structure.
type ArkServiceOnboardReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceOnboardReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceOnboardOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceOnboardDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceOnboardOK creates a ArkServiceOnboardOK with default headers values
func NewArkServiceOnboardOK() *ArkServiceOnboardOK {
return &ArkServiceOnboardOK{}
}
/*ArkServiceOnboardOK handles this case with default header values.
A successful response.
*/
type ArkServiceOnboardOK struct {
Payload models.V1OnboardResponse
}
func (o *ArkServiceOnboardOK) Error() string {
return fmt.Sprintf("[POST /v1/onboard][%d] arkServiceOnboardOK %+v", 200, o.Payload)
}
func (o *ArkServiceOnboardOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
// response payload
if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceOnboardDefault creates a ArkServiceOnboardDefault with default headers values
func NewArkServiceOnboardDefault(code int) *ArkServiceOnboardDefault {
return &ArkServiceOnboardDefault{
_statusCode: code,
}
}
/*ArkServiceOnboardDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceOnboardDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service onboard default response
func (o *ArkServiceOnboardDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceOnboardDefault) Error() string {
return fmt.Sprintf("[POST /v1/onboard][%d] ArkService_Onboard default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceOnboardDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,133 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
)
// NewArkServicePingParams creates a new ArkServicePingParams object
// with the default values initialized.
func NewArkServicePingParams() *ArkServicePingParams {
var ()
return &ArkServicePingParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServicePingParamsWithTimeout creates a new ArkServicePingParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServicePingParamsWithTimeout(timeout time.Duration) *ArkServicePingParams {
var ()
return &ArkServicePingParams{
timeout: timeout,
}
}
// NewArkServicePingParamsWithContext creates a new ArkServicePingParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServicePingParamsWithContext(ctx context.Context) *ArkServicePingParams {
var ()
return &ArkServicePingParams{
Context: ctx,
}
}
// NewArkServicePingParamsWithHTTPClient creates a new ArkServicePingParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServicePingParamsWithHTTPClient(client *http.Client) *ArkServicePingParams {
var ()
return &ArkServicePingParams{
HTTPClient: client,
}
}
/*ArkServicePingParams contains all the parameters to send to the API endpoint
for the ark service ping operation typically these are written to a http.Request
*/
type ArkServicePingParams struct {
/*PaymentID*/
PaymentID string
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service ping params
func (o *ArkServicePingParams) WithTimeout(timeout time.Duration) *ArkServicePingParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service ping params
func (o *ArkServicePingParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service ping params
func (o *ArkServicePingParams) WithContext(ctx context.Context) *ArkServicePingParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service ping params
func (o *ArkServicePingParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service ping params
func (o *ArkServicePingParams) WithHTTPClient(client *http.Client) *ArkServicePingParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service ping params
func (o *ArkServicePingParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithPaymentID adds the paymentID to the ark service ping params
func (o *ArkServicePingParams) WithPaymentID(paymentID string) *ArkServicePingParams {
o.SetPaymentID(paymentID)
return o
}
// SetPaymentID adds the paymentId to the ark service ping params
func (o *ArkServicePingParams) SetPaymentID(paymentID string) {
o.PaymentID = paymentID
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServicePingParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
// path param paymentId
if err := r.SetPathParam("paymentId", o.PaymentID); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServicePingReader is a Reader for the ArkServicePing structure.
type ArkServicePingReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServicePingReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServicePingOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServicePingDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServicePingOK creates a ArkServicePingOK with default headers values
func NewArkServicePingOK() *ArkServicePingOK {
return &ArkServicePingOK{}
}
/*ArkServicePingOK handles this case with default header values.
A successful response.
*/
type ArkServicePingOK struct {
Payload *models.V1PingResponse
}
func (o *ArkServicePingOK) Error() string {
return fmt.Sprintf("[GET /v1/ping/{paymentId}][%d] arkServicePingOK %+v", 200, o.Payload)
}
func (o *ArkServicePingOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1PingResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServicePingDefault creates a ArkServicePingDefault with default headers values
func NewArkServicePingDefault(code int) *ArkServicePingDefault {
return &ArkServicePingDefault{
_statusCode: code,
}
}
/*ArkServicePingDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServicePingDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service ping default response
func (o *ArkServicePingDefault) Code() int {
return o._statusCode
}
func (o *ArkServicePingDefault) Error() string {
return fmt.Sprintf("[GET /v1/ping/{paymentId}][%d] ArkService_Ping default %+v", o._statusCode, o.Payload)
}
func (o *ArkServicePingDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// NewArkServiceRegisterPaymentParams creates a new ArkServiceRegisterPaymentParams object
// with the default values initialized.
func NewArkServiceRegisterPaymentParams() *ArkServiceRegisterPaymentParams {
var ()
return &ArkServiceRegisterPaymentParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceRegisterPaymentParamsWithTimeout creates a new ArkServiceRegisterPaymentParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceRegisterPaymentParamsWithTimeout(timeout time.Duration) *ArkServiceRegisterPaymentParams {
var ()
return &ArkServiceRegisterPaymentParams{
timeout: timeout,
}
}
// NewArkServiceRegisterPaymentParamsWithContext creates a new ArkServiceRegisterPaymentParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceRegisterPaymentParamsWithContext(ctx context.Context) *ArkServiceRegisterPaymentParams {
var ()
return &ArkServiceRegisterPaymentParams{
Context: ctx,
}
}
// NewArkServiceRegisterPaymentParamsWithHTTPClient creates a new ArkServiceRegisterPaymentParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceRegisterPaymentParamsWithHTTPClient(client *http.Client) *ArkServiceRegisterPaymentParams {
var ()
return &ArkServiceRegisterPaymentParams{
HTTPClient: client,
}
}
/*ArkServiceRegisterPaymentParams contains all the parameters to send to the API endpoint
for the ark service register payment operation typically these are written to a http.Request
*/
type ArkServiceRegisterPaymentParams struct {
/*Body*/
Body *models.V1RegisterPaymentRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) WithTimeout(timeout time.Duration) *ArkServiceRegisterPaymentParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) WithContext(ctx context.Context) *ArkServiceRegisterPaymentParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) WithHTTPClient(client *http.Client) *ArkServiceRegisterPaymentParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) WithBody(body *models.V1RegisterPaymentRequest) *ArkServiceRegisterPaymentParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the ark service register payment params
func (o *ArkServiceRegisterPaymentParams) SetBody(body *models.V1RegisterPaymentRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceRegisterPaymentParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceRegisterPaymentReader is a Reader for the ArkServiceRegisterPayment structure.
type ArkServiceRegisterPaymentReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceRegisterPaymentReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceRegisterPaymentOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceRegisterPaymentDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceRegisterPaymentOK creates a ArkServiceRegisterPaymentOK with default headers values
func NewArkServiceRegisterPaymentOK() *ArkServiceRegisterPaymentOK {
return &ArkServiceRegisterPaymentOK{}
}
/*ArkServiceRegisterPaymentOK handles this case with default header values.
A successful response.
*/
type ArkServiceRegisterPaymentOK struct {
Payload *models.V1RegisterPaymentResponse
}
func (o *ArkServiceRegisterPaymentOK) Error() string {
return fmt.Sprintf("[POST /v1/payment/register][%d] arkServiceRegisterPaymentOK %+v", 200, o.Payload)
}
func (o *ArkServiceRegisterPaymentOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1RegisterPaymentResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceRegisterPaymentDefault creates a ArkServiceRegisterPaymentDefault with default headers values
func NewArkServiceRegisterPaymentDefault(code int) *ArkServiceRegisterPaymentDefault {
return &ArkServiceRegisterPaymentDefault{
_statusCode: code,
}
}
/*ArkServiceRegisterPaymentDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceRegisterPaymentDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service register payment default response
func (o *ArkServiceRegisterPaymentDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceRegisterPaymentDefault) Error() string {
return fmt.Sprintf("[POST /v1/payment/register][%d] ArkService_RegisterPayment default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceRegisterPaymentDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,136 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"context"
"net/http"
"time"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime"
cr "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// NewArkServiceTrustedOnboardingParams creates a new ArkServiceTrustedOnboardingParams object
// with the default values initialized.
func NewArkServiceTrustedOnboardingParams() *ArkServiceTrustedOnboardingParams {
var ()
return &ArkServiceTrustedOnboardingParams{
timeout: cr.DefaultTimeout,
}
}
// NewArkServiceTrustedOnboardingParamsWithTimeout creates a new ArkServiceTrustedOnboardingParams object
// with the default values initialized, and the ability to set a timeout on a request
func NewArkServiceTrustedOnboardingParamsWithTimeout(timeout time.Duration) *ArkServiceTrustedOnboardingParams {
var ()
return &ArkServiceTrustedOnboardingParams{
timeout: timeout,
}
}
// NewArkServiceTrustedOnboardingParamsWithContext creates a new ArkServiceTrustedOnboardingParams object
// with the default values initialized, and the ability to set a context for a request
func NewArkServiceTrustedOnboardingParamsWithContext(ctx context.Context) *ArkServiceTrustedOnboardingParams {
var ()
return &ArkServiceTrustedOnboardingParams{
Context: ctx,
}
}
// NewArkServiceTrustedOnboardingParamsWithHTTPClient creates a new ArkServiceTrustedOnboardingParams object
// with the default values initialized, and the ability to set a custom HTTPClient for a request
func NewArkServiceTrustedOnboardingParamsWithHTTPClient(client *http.Client) *ArkServiceTrustedOnboardingParams {
var ()
return &ArkServiceTrustedOnboardingParams{
HTTPClient: client,
}
}
/*ArkServiceTrustedOnboardingParams contains all the parameters to send to the API endpoint
for the ark service trusted onboarding operation typically these are written to a http.Request
*/
type ArkServiceTrustedOnboardingParams struct {
/*Body*/
Body *models.V1TrustedOnboardingRequest
timeout time.Duration
Context context.Context
HTTPClient *http.Client
}
// WithTimeout adds the timeout to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) WithTimeout(timeout time.Duration) *ArkServiceTrustedOnboardingParams {
o.SetTimeout(timeout)
return o
}
// SetTimeout adds the timeout to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) SetTimeout(timeout time.Duration) {
o.timeout = timeout
}
// WithContext adds the context to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) WithContext(ctx context.Context) *ArkServiceTrustedOnboardingParams {
o.SetContext(ctx)
return o
}
// SetContext adds the context to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) SetContext(ctx context.Context) {
o.Context = ctx
}
// WithHTTPClient adds the HTTPClient to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) WithHTTPClient(client *http.Client) *ArkServiceTrustedOnboardingParams {
o.SetHTTPClient(client)
return o
}
// SetHTTPClient adds the HTTPClient to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) SetHTTPClient(client *http.Client) {
o.HTTPClient = client
}
// WithBody adds the body to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) WithBody(body *models.V1TrustedOnboardingRequest) *ArkServiceTrustedOnboardingParams {
o.SetBody(body)
return o
}
// SetBody adds the body to the ark service trusted onboarding params
func (o *ArkServiceTrustedOnboardingParams) SetBody(body *models.V1TrustedOnboardingRequest) {
o.Body = body
}
// WriteToRequest writes these params to a swagger request
func (o *ArkServiceTrustedOnboardingParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
if err := r.SetTimeout(o.timeout); err != nil {
return err
}
var res []error
if o.Body != nil {
if err := r.SetBodyParam(o.Body); err != nil {
return err
}
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package ark_service
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"fmt"
"io"
"github.com/go-openapi/runtime"
strfmt "github.com/go-openapi/strfmt"
models "github.com/ark-network/ark-sdk/rest/service/models"
)
// ArkServiceTrustedOnboardingReader is a Reader for the ArkServiceTrustedOnboarding structure.
type ArkServiceTrustedOnboardingReader struct {
formats strfmt.Registry
}
// ReadResponse reads a server response into the received o.
func (o *ArkServiceTrustedOnboardingReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) {
switch response.Code() {
case 200:
result := NewArkServiceTrustedOnboardingOK()
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
return result, nil
default:
result := NewArkServiceTrustedOnboardingDefault(response.Code())
if err := result.readResponse(response, consumer, o.formats); err != nil {
return nil, err
}
if response.Code()/100 == 2 {
return result, nil
}
return nil, result
}
}
// NewArkServiceTrustedOnboardingOK creates a ArkServiceTrustedOnboardingOK with default headers values
func NewArkServiceTrustedOnboardingOK() *ArkServiceTrustedOnboardingOK {
return &ArkServiceTrustedOnboardingOK{}
}
/*ArkServiceTrustedOnboardingOK handles this case with default header values.
A successful response.
*/
type ArkServiceTrustedOnboardingOK struct {
Payload *models.V1TrustedOnboardingResponse
}
func (o *ArkServiceTrustedOnboardingOK) Error() string {
return fmt.Sprintf("[POST /v1/onboard/address][%d] arkServiceTrustedOnboardingOK %+v", 200, o.Payload)
}
func (o *ArkServiceTrustedOnboardingOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.V1TrustedOnboardingResponse)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}
// NewArkServiceTrustedOnboardingDefault creates a ArkServiceTrustedOnboardingDefault with default headers values
func NewArkServiceTrustedOnboardingDefault(code int) *ArkServiceTrustedOnboardingDefault {
return &ArkServiceTrustedOnboardingDefault{
_statusCode: code,
}
}
/*ArkServiceTrustedOnboardingDefault handles this case with default header values.
An unexpected error response.
*/
type ArkServiceTrustedOnboardingDefault struct {
_statusCode int
Payload *models.RPCStatus
}
// Code gets the status code for the ark service trusted onboarding default response
func (o *ArkServiceTrustedOnboardingDefault) Code() int {
return o._statusCode
}
func (o *ArkServiceTrustedOnboardingDefault) Error() string {
return fmt.Sprintf("[POST /v1/onboard/address][%d] ArkService_TrustedOnboarding default %+v", o._statusCode, o.Payload)
}
func (o *ArkServiceTrustedOnboardingDefault) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
o.Payload = new(models.RPCStatus)
// response payload
if err := consumer.Consume(response.Body(), o.Payload); err != nil && err != io.EOF {
return err
}
return nil
}

View File

@@ -0,0 +1,117 @@
// Code generated by go-swagger; DO NOT EDIT.
package arkservicerestclient
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"github.com/go-openapi/runtime"
httptransport "github.com/go-openapi/runtime/client"
strfmt "github.com/go-openapi/strfmt"
"github.com/ark-network/ark-sdk/rest/service/arkservicerestclient/ark_service"
)
// Default ark v1 service proto HTTP client.
var Default = NewHTTPClient(nil)
const (
// DefaultHost is the default Host
// found in Meta (info) section of spec file
DefaultHost string = "localhost"
// DefaultBasePath is the default BasePath
// found in Meta (info) section of spec file
DefaultBasePath string = "/"
)
// DefaultSchemes are the default schemes found in Meta (info) section of spec file
var DefaultSchemes = []string{"http"}
// NewHTTPClient creates a new ark v1 service proto HTTP client.
func NewHTTPClient(formats strfmt.Registry) *ArkV1ServiceProto {
return NewHTTPClientWithConfig(formats, nil)
}
// NewHTTPClientWithConfig creates a new ark v1 service proto HTTP client,
// using a customizable transport config.
func NewHTTPClientWithConfig(formats strfmt.Registry, cfg *TransportConfig) *ArkV1ServiceProto {
// ensure nullable parameters have default
if cfg == nil {
cfg = DefaultTransportConfig()
}
// create transport and client
transport := httptransport.New(cfg.Host, cfg.BasePath, cfg.Schemes)
return New(transport, formats)
}
// New creates a new ark v1 service proto client
func New(transport runtime.ClientTransport, formats strfmt.Registry) *ArkV1ServiceProto {
// ensure nullable parameters have default
if formats == nil {
formats = strfmt.Default
}
cli := new(ArkV1ServiceProto)
cli.Transport = transport
cli.ArkService = ark_service.New(transport, formats)
return cli
}
// DefaultTransportConfig creates a TransportConfig with the
// default settings taken from the meta section of the spec file.
func DefaultTransportConfig() *TransportConfig {
return &TransportConfig{
Host: DefaultHost,
BasePath: DefaultBasePath,
Schemes: DefaultSchemes,
}
}
// TransportConfig contains the transport related info,
// found in the meta section of the spec file.
type TransportConfig struct {
Host string
BasePath string
Schemes []string
}
// WithHost overrides the default host,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithHost(host string) *TransportConfig {
cfg.Host = host
return cfg
}
// WithBasePath overrides the default basePath,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithBasePath(basePath string) *TransportConfig {
cfg.BasePath = basePath
return cfg
}
// WithSchemes overrides the default schemes,
// provided by the meta section of the spec file.
func (cfg *TransportConfig) WithSchemes(schemes []string) *TransportConfig {
cfg.Schemes = schemes
return cfg
}
// ArkV1ServiceProto is a client for ark v1 service proto
type ArkV1ServiceProto struct {
ArkService *ark_service.Client
Transport runtime.ClientTransport
}
// SetTransport changes the transport on the client and all its subresources
func (c *ArkV1ServiceProto) SetTransport(transport runtime.ClientTransport) {
c.Transport = transport
c.ArkService.SetTransport(transport)
}

View File

@@ -0,0 +1,43 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// ProtobufAny protobuf any
// swagger:model protobufAny
type ProtobufAny struct {
// at type
AtType string `json:"@type,omitempty"`
}
// Validate validates this protobuf any
func (m *ProtobufAny) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *ProtobufAny) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *ProtobufAny) UnmarshalBinary(b []byte) error {
var res ProtobufAny
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,86 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// RPCStatus rpc status
// swagger:model rpcStatus
type RPCStatus struct {
// code
Code int32 `json:"code,omitempty"`
// details
Details []*ProtobufAny `json:"details"`
// message
Message string `json:"message,omitempty"`
}
// Validate validates this rpc status
func (m *RPCStatus) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateDetails(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *RPCStatus) validateDetails(formats strfmt.Registry) error {
if swag.IsZero(m.Details) { // not required
return nil
}
for i := 0; i < len(m.Details); i++ {
if swag.IsZero(m.Details[i]) { // not required
continue
}
if m.Details[i] != nil {
if err := m.Details[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("details" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *RPCStatus) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *RPCStatus) UnmarshalBinary(b []byte) error {
var res RPCStatus
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,83 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1ClaimPaymentRequest v1 claim payment request
// swagger:model v1ClaimPaymentRequest
type V1ClaimPaymentRequest struct {
// Mocks wabisabi's credentials.
ID string `json:"id,omitempty"`
// List of receivers for a registered payment.
Outputs []*V1Output `json:"outputs"`
}
// Validate validates this v1 claim payment request
func (m *V1ClaimPaymentRequest) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateOutputs(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1ClaimPaymentRequest) validateOutputs(formats strfmt.Registry) error {
if swag.IsZero(m.Outputs) { // not required
return nil
}
for i := 0; i < len(m.Outputs); i++ {
if swag.IsZero(m.Outputs[i]) { // not required
continue
}
if m.Outputs[i] != nil {
if err := m.Outputs[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("outputs" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1ClaimPaymentRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1ClaimPaymentRequest) UnmarshalBinary(b []byte) error {
var res V1ClaimPaymentRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,10 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// V1ClaimPaymentResponse v1 claim payment response
// swagger:model v1ClaimPaymentResponse
type V1ClaimPaymentResponse interface{}

View File

@@ -0,0 +1,43 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1FinalizePaymentRequest v1 finalize payment request
// swagger:model v1FinalizePaymentRequest
type V1FinalizePaymentRequest struct {
// Forfeit txs signed by the user.
SignedForfeitTxs []string `json:"signedForfeitTxs"`
}
// Validate validates this v1 finalize payment request
func (m *V1FinalizePaymentRequest) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1FinalizePaymentRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1FinalizePaymentRequest) UnmarshalBinary(b []byte) error {
var res V1FinalizePaymentRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,10 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// V1FinalizePaymentResponse v1 finalize payment response
// swagger:model v1FinalizePaymentResponse
type V1FinalizePaymentResponse interface{}

View File

@@ -0,0 +1,121 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1GetEventStreamResponse v1 get event stream response
// swagger:model v1GetEventStreamResponse
type V1GetEventStreamResponse struct {
// round failed
RoundFailed *V1RoundFailed `json:"roundFailed,omitempty"`
// TODO: BTC add "signTree" event
RoundFinalization *V1RoundFinalizationEvent `json:"roundFinalization,omitempty"`
// round finalized
RoundFinalized *V1RoundFinalizedEvent `json:"roundFinalized,omitempty"`
}
// Validate validates this v1 get event stream response
func (m *V1GetEventStreamResponse) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateRoundFailed(formats); err != nil {
res = append(res, err)
}
if err := m.validateRoundFinalization(formats); err != nil {
res = append(res, err)
}
if err := m.validateRoundFinalized(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1GetEventStreamResponse) validateRoundFailed(formats strfmt.Registry) error {
if swag.IsZero(m.RoundFailed) { // not required
return nil
}
if m.RoundFailed != nil {
if err := m.RoundFailed.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("roundFailed")
}
return err
}
}
return nil
}
func (m *V1GetEventStreamResponse) validateRoundFinalization(formats strfmt.Registry) error {
if swag.IsZero(m.RoundFinalization) { // not required
return nil
}
if m.RoundFinalization != nil {
if err := m.RoundFinalization.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("roundFinalization")
}
return err
}
}
return nil
}
func (m *V1GetEventStreamResponse) validateRoundFinalized(formats strfmt.Registry) error {
if swag.IsZero(m.RoundFinalized) { // not required
return nil
}
if m.RoundFinalized != nil {
if err := m.RoundFinalized.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("roundFinalized")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1GetEventStreamResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetEventStreamResponse) UnmarshalBinary(b []byte) error {
var res V1GetEventStreamResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,58 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1GetInfoResponse v1 get info response
// swagger:model v1GetInfoResponse
type V1GetInfoResponse struct {
// min relay fee
MinRelayFee string `json:"minRelayFee,omitempty"`
// network
Network string `json:"network,omitempty"`
// pubkey
Pubkey string `json:"pubkey,omitempty"`
// round interval
RoundInterval string `json:"roundInterval,omitempty"`
// round lifetime
RoundLifetime string `json:"roundLifetime,omitempty"`
// unilateral exit delay
UnilateralExitDelay string `json:"unilateralExitDelay,omitempty"`
}
// Validate validates this v1 get info response
func (m *V1GetInfoResponse) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1GetInfoResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetInfoResponse) UnmarshalBinary(b []byte) error {
var res V1GetInfoResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,71 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1GetRoundByIDResponse v1 get round by Id response
// swagger:model v1GetRoundByIdResponse
type V1GetRoundByIDResponse struct {
// round
Round *V1Round `json:"round,omitempty"`
}
// Validate validates this v1 get round by Id response
func (m *V1GetRoundByIDResponse) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateRound(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1GetRoundByIDResponse) validateRound(formats strfmt.Registry) error {
if swag.IsZero(m.Round) { // not required
return nil
}
if m.Round != nil {
if err := m.Round.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("round")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1GetRoundByIDResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetRoundByIDResponse) UnmarshalBinary(b []byte) error {
var res V1GetRoundByIDResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,71 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1GetRoundResponse v1 get round response
// swagger:model v1GetRoundResponse
type V1GetRoundResponse struct {
// round
Round *V1Round `json:"round,omitempty"`
}
// Validate validates this v1 get round response
func (m *V1GetRoundResponse) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateRound(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1GetRoundResponse) validateRound(formats strfmt.Registry) error {
if swag.IsZero(m.Round) { // not required
return nil
}
if m.Round != nil {
if err := m.Round.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("round")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1GetRoundResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1GetRoundResponse) UnmarshalBinary(b []byte) error {
var res V1GetRoundResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,46 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1Input v1 input
// swagger:model v1Input
type V1Input struct {
// txid
Txid string `json:"txid,omitempty"`
// vout
Vout int64 `json:"vout,omitempty"`
}
// Validate validates this v1 input
func (m *V1Input) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1Input) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1Input) UnmarshalBinary(b []byte) error {
var res V1Input
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1ListVtxosResponse v1 list vtxos response
// swagger:model v1ListVtxosResponse
type V1ListVtxosResponse struct {
// spendable vtxos
SpendableVtxos []*V1Vtxo `json:"spendableVtxos"`
// spent vtxos
SpentVtxos []*V1Vtxo `json:"spentVtxos"`
}
// Validate validates this v1 list vtxos response
func (m *V1ListVtxosResponse) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateSpendableVtxos(formats); err != nil {
res = append(res, err)
}
if err := m.validateSpentVtxos(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1ListVtxosResponse) validateSpendableVtxos(formats strfmt.Registry) error {
if swag.IsZero(m.SpendableVtxos) { // not required
return nil
}
for i := 0; i < len(m.SpendableVtxos); i++ {
if swag.IsZero(m.SpendableVtxos[i]) { // not required
continue
}
if m.SpendableVtxos[i] != nil {
if err := m.SpendableVtxos[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("spendableVtxos" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
func (m *V1ListVtxosResponse) validateSpentVtxos(formats strfmt.Registry) error {
if swag.IsZero(m.SpentVtxos) { // not required
return nil
}
for i := 0; i < len(m.SpentVtxos); i++ {
if swag.IsZero(m.SpentVtxos[i]) { // not required
continue
}
if m.SpentVtxos[i] != nil {
if err := m.SpentVtxos[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("spentVtxos" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1ListVtxosResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1ListVtxosResponse) UnmarshalBinary(b []byte) error {
var res V1ListVtxosResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,49 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1Node v1 node
// swagger:model v1Node
type V1Node struct {
// parent txid
ParentTxid string `json:"parentTxid,omitempty"`
// tx
Tx string `json:"tx,omitempty"`
// txid
Txid string `json:"txid,omitempty"`
}
// Validate validates this v1 node
func (m *V1Node) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1Node) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1Node) UnmarshalBinary(b []byte) error {
var res V1Node
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,77 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1OnboardRequest v1 onboard request
// swagger:model v1OnboardRequest
type V1OnboardRequest struct {
// boarding tx
BoardingTx string `json:"boardingTx,omitempty"`
// congestion tree
CongestionTree *V1Tree `json:"congestionTree,omitempty"`
// user pubkey
UserPubkey string `json:"userPubkey,omitempty"`
}
// Validate validates this v1 onboard request
func (m *V1OnboardRequest) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCongestionTree(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1OnboardRequest) validateCongestionTree(formats strfmt.Registry) error {
if swag.IsZero(m.CongestionTree) { // not required
return nil
}
if m.CongestionTree != nil {
if err := m.CongestionTree.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("congestionTree")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1OnboardRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1OnboardRequest) UnmarshalBinary(b []byte) error {
var res V1OnboardRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,10 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// V1OnboardResponse v1 onboard response
// swagger:model v1OnboardResponse
type V1OnboardResponse interface{}

View File

@@ -0,0 +1,46 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1Output v1 output
// swagger:model v1Output
type V1Output struct {
// Either the offchain or onchain address.
Address string `json:"address,omitempty"`
// Amount to send in satoshis.
Amount string `json:"amount,omitempty"`
}
// Validate validates this v1 output
func (m *V1Output) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1Output) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1Output) UnmarshalBinary(b []byte) error {
var res V1Output
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,74 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1PingResponse v1 ping response
// swagger:model v1PingResponse
type V1PingResponse struct {
// event
Event *V1RoundFinalizationEvent `json:"event,omitempty"`
// forfeit txs
ForfeitTxs []string `json:"forfeitTxs"`
}
// Validate validates this v1 ping response
func (m *V1PingResponse) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateEvent(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1PingResponse) validateEvent(formats strfmt.Registry) error {
if swag.IsZero(m.Event) { // not required
return nil
}
if m.Event != nil {
if err := m.Event.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("event")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1PingResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1PingResponse) UnmarshalBinary(b []byte) error {
var res V1PingResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,80 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1RegisterPaymentRequest v1 register payment request
// swagger:model v1RegisterPaymentRequest
type V1RegisterPaymentRequest struct {
// inputs
Inputs []*V1Input `json:"inputs"`
}
// Validate validates this v1 register payment request
func (m *V1RegisterPaymentRequest) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateInputs(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1RegisterPaymentRequest) validateInputs(formats strfmt.Registry) error {
if swag.IsZero(m.Inputs) { // not required
return nil
}
for i := 0; i < len(m.Inputs); i++ {
if swag.IsZero(m.Inputs[i]) { // not required
continue
}
if m.Inputs[i] != nil {
if err := m.Inputs[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("inputs" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1RegisterPaymentRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1RegisterPaymentRequest) UnmarshalBinary(b []byte) error {
var res V1RegisterPaymentRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,43 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1RegisterPaymentResponse v1 register payment response
// swagger:model v1RegisterPaymentResponse
type V1RegisterPaymentResponse struct {
// Mocks wabisabi's credentials.
ID string `json:"id,omitempty"`
}
// Validate validates this v1 register payment response
func (m *V1RegisterPaymentResponse) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1RegisterPaymentResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1RegisterPaymentResponse) UnmarshalBinary(b []byte) error {
var res V1RegisterPaymentResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,112 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1Round v1 round
// swagger:model v1Round
type V1Round struct {
// congestion tree
CongestionTree *V1Tree `json:"congestionTree,omitempty"`
// connectors
Connectors []string `json:"connectors"`
// end
End string `json:"end,omitempty"`
// forfeit txs
ForfeitTxs []string `json:"forfeitTxs"`
// id
ID string `json:"id,omitempty"`
// pool tx
PoolTx string `json:"poolTx,omitempty"`
// stage
Stage V1RoundStage `json:"stage,omitempty"`
// start
Start string `json:"start,omitempty"`
}
// Validate validates this v1 round
func (m *V1Round) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCongestionTree(formats); err != nil {
res = append(res, err)
}
if err := m.validateStage(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1Round) validateCongestionTree(formats strfmt.Registry) error {
if swag.IsZero(m.CongestionTree) { // not required
return nil
}
if m.CongestionTree != nil {
if err := m.CongestionTree.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("congestionTree")
}
return err
}
}
return nil
}
func (m *V1Round) validateStage(formats strfmt.Registry) error {
if swag.IsZero(m.Stage) { // not required
return nil
}
if err := m.Stage.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("stage")
}
return err
}
return nil
}
// MarshalBinary interface implementation
func (m *V1Round) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1Round) UnmarshalBinary(b []byte) error {
var res V1Round
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,46 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1RoundFailed v1 round failed
// swagger:model v1RoundFailed
type V1RoundFailed struct {
// id
ID string `json:"id,omitempty"`
// reason
Reason string `json:"reason,omitempty"`
}
// Validate validates this v1 round failed
func (m *V1RoundFailed) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1RoundFailed) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1RoundFailed) UnmarshalBinary(b []byte) error {
var res V1RoundFailed
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,83 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1RoundFinalizationEvent v1 round finalization event
// swagger:model v1RoundFinalizationEvent
type V1RoundFinalizationEvent struct {
// congestion tree
CongestionTree *V1Tree `json:"congestionTree,omitempty"`
// connectors
Connectors []string `json:"connectors"`
// forfeit txs
ForfeitTxs []string `json:"forfeitTxs"`
// id
ID string `json:"id,omitempty"`
// pool tx
PoolTx string `json:"poolTx,omitempty"`
}
// Validate validates this v1 round finalization event
func (m *V1RoundFinalizationEvent) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateCongestionTree(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1RoundFinalizationEvent) validateCongestionTree(formats strfmt.Registry) error {
if swag.IsZero(m.CongestionTree) { // not required
return nil
}
if m.CongestionTree != nil {
if err := m.CongestionTree.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("congestionTree")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1RoundFinalizationEvent) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1RoundFinalizationEvent) UnmarshalBinary(b []byte) error {
var res V1RoundFinalizationEvent
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,46 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1RoundFinalizedEvent v1 round finalized event
// swagger:model v1RoundFinalizedEvent
type V1RoundFinalizedEvent struct {
// id
ID string `json:"id,omitempty"`
// pool txid
PoolTxid string `json:"poolTxid,omitempty"`
}
// Validate validates this v1 round finalized event
func (m *V1RoundFinalizedEvent) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1RoundFinalizedEvent) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1RoundFinalizedEvent) UnmarshalBinary(b []byte) error {
var res V1RoundFinalizedEvent
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,72 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"encoding/json"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/validate"
)
// V1RoundStage v1 round stage
// swagger:model v1RoundStage
type V1RoundStage string
const (
// V1RoundStageROUNDSTAGEUNSPECIFIED captures enum value "ROUND_STAGE_UNSPECIFIED"
V1RoundStageROUNDSTAGEUNSPECIFIED V1RoundStage = "ROUND_STAGE_UNSPECIFIED"
// V1RoundStageROUNDSTAGEREGISTRATION captures enum value "ROUND_STAGE_REGISTRATION"
V1RoundStageROUNDSTAGEREGISTRATION V1RoundStage = "ROUND_STAGE_REGISTRATION"
// V1RoundStageROUNDSTAGEFINALIZATION captures enum value "ROUND_STAGE_FINALIZATION"
V1RoundStageROUNDSTAGEFINALIZATION V1RoundStage = "ROUND_STAGE_FINALIZATION"
// V1RoundStageROUNDSTAGEFINALIZED captures enum value "ROUND_STAGE_FINALIZED"
V1RoundStageROUNDSTAGEFINALIZED V1RoundStage = "ROUND_STAGE_FINALIZED"
// V1RoundStageROUNDSTAGEFAILED captures enum value "ROUND_STAGE_FAILED"
V1RoundStageROUNDSTAGEFAILED V1RoundStage = "ROUND_STAGE_FAILED"
)
// for schema
var v1RoundStageEnum []interface{}
func init() {
var res []V1RoundStage
if err := json.Unmarshal([]byte(`["ROUND_STAGE_UNSPECIFIED","ROUND_STAGE_REGISTRATION","ROUND_STAGE_FINALIZATION","ROUND_STAGE_FINALIZED","ROUND_STAGE_FAILED"]`), &res); err != nil {
panic(err)
}
for _, v := range res {
v1RoundStageEnum = append(v1RoundStageEnum, v)
}
}
func (m V1RoundStage) validateV1RoundStageEnum(path, location string, value V1RoundStage) error {
if err := validate.Enum(path, location, value, v1RoundStageEnum); err != nil {
return err
}
return nil
}
// Validate validates this v1 round stage
func (m V1RoundStage) Validate(formats strfmt.Registry) error {
var res []error
// value enum
if err := m.validateV1RoundStageEnum("", "body", m); err != nil {
return err
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}

View File

@@ -0,0 +1,80 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1Tree v1 tree
// swagger:model v1Tree
type V1Tree struct {
// levels
Levels []*V1TreeLevel `json:"levels"`
}
// Validate validates this v1 tree
func (m *V1Tree) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateLevels(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1Tree) validateLevels(formats strfmt.Registry) error {
if swag.IsZero(m.Levels) { // not required
return nil
}
for i := 0; i < len(m.Levels); i++ {
if swag.IsZero(m.Levels[i]) { // not required
continue
}
if m.Levels[i] != nil {
if err := m.Levels[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("levels" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1Tree) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1Tree) UnmarshalBinary(b []byte) error {
var res V1Tree
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,80 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1TreeLevel v1 tree level
// swagger:model v1TreeLevel
type V1TreeLevel struct {
// nodes
Nodes []*V1Node `json:"nodes"`
}
// Validate validates this v1 tree level
func (m *V1TreeLevel) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateNodes(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1TreeLevel) validateNodes(formats strfmt.Registry) error {
if swag.IsZero(m.Nodes) { // not required
return nil
}
for i := 0; i < len(m.Nodes); i++ {
if swag.IsZero(m.Nodes[i]) { // not required
continue
}
if m.Nodes[i] != nil {
if err := m.Nodes[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("nodes" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1TreeLevel) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1TreeLevel) UnmarshalBinary(b []byte) error {
var res V1TreeLevel
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,43 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1TrustedOnboardingRequest v1 trusted onboarding request
// swagger:model v1TrustedOnboardingRequest
type V1TrustedOnboardingRequest struct {
// user pubkey
UserPubkey string `json:"userPubkey,omitempty"`
}
// Validate validates this v1 trusted onboarding request
func (m *V1TrustedOnboardingRequest) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1TrustedOnboardingRequest) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1TrustedOnboardingRequest) UnmarshalBinary(b []byte) error {
var res V1TrustedOnboardingRequest
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,43 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// V1TrustedOnboardingResponse v1 trusted onboarding response
// swagger:model v1TrustedOnboardingResponse
type V1TrustedOnboardingResponse struct {
// address
Address string `json:"address,omitempty"`
}
// Validate validates this v1 trusted onboarding response
func (m *V1TrustedOnboardingResponse) Validate(formats strfmt.Registry) error {
return nil
}
// MarshalBinary interface implementation
func (m *V1TrustedOnboardingResponse) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1TrustedOnboardingResponse) UnmarshalBinary(b []byte) error {
var res V1TrustedOnboardingResponse
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

View File

@@ -0,0 +1,111 @@
// Code generated by go-swagger; DO NOT EDIT.
package models
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
strfmt "github.com/go-openapi/strfmt"
"github.com/go-openapi/errors"
"github.com/go-openapi/swag"
)
// V1Vtxo v1 vtxo
// swagger:model v1Vtxo
type V1Vtxo struct {
// expire at
ExpireAt string `json:"expireAt,omitempty"`
// outpoint
Outpoint *V1Input `json:"outpoint,omitempty"`
// pool txid
PoolTxid string `json:"poolTxid,omitempty"`
// receiver
Receiver *V1Output `json:"receiver,omitempty"`
// spent
Spent bool `json:"spent,omitempty"`
// spent by
SpentBy string `json:"spentBy,omitempty"`
// swept
Swept bool `json:"swept,omitempty"`
}
// Validate validates this v1 vtxo
func (m *V1Vtxo) Validate(formats strfmt.Registry) error {
var res []error
if err := m.validateOutpoint(formats); err != nil {
res = append(res, err)
}
if err := m.validateReceiver(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *V1Vtxo) validateOutpoint(formats strfmt.Registry) error {
if swag.IsZero(m.Outpoint) { // not required
return nil
}
if m.Outpoint != nil {
if err := m.Outpoint.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("outpoint")
}
return err
}
}
return nil
}
func (m *V1Vtxo) validateReceiver(formats strfmt.Registry) error {
if swag.IsZero(m.Receiver) { // not required
return nil
}
if m.Receiver != nil {
if err := m.Receiver.Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("receiver")
}
return err
}
}
return nil
}
// MarshalBinary interface implementation
func (m *V1Vtxo) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *V1Vtxo) UnmarshalBinary(b []byte) error {
var res V1Vtxo
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}

29
pkg/client-sdk/store.go Normal file
View File

@@ -0,0 +1,29 @@
package arksdk
import (
"context"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
)
type ConfigStore interface {
GetAspUrl(ctx context.Context) (string, error)
GetAspPubKeyHex(ctx context.Context) (string, error)
GetTransportProtocol(ctx context.Context) (TransportProtocol, error)
GetExplorerUrl(ctx context.Context) (string, error)
GetNetwork(ctx context.Context) (string, error)
SetAspUrl(aspUrl string)
SetAspPubKeyHex(aspPubKeyHex string)
SetTransportProtocol(protocol TransportProtocol)
SetExplorerUrl(explorerUrl string)
SetNetwork(net string)
Save(ctx context.Context) error
}
type WalletStore interface {
CreatePrivateKey() (*secp256k1.PrivateKey, error)
GetPrivateKeyHex() (string, error)
Save(ctx context.Context) error
}

View File

@@ -0,0 +1,78 @@
package inmemorystore
import (
"context"
"errors"
arksdk "github.com/ark-network/ark-sdk"
)
type configStore struct {
aspUrl string
protocol arksdk.TransportProtocol
explorerUrl string
net string
aspPubKeyHex string
}
func New(
aspUrl string, protocol arksdk.TransportProtocol,
) (arksdk.ConfigStore, error) {
if aspUrl == "" {
return nil, errors.New("aspUrl cannot be empty")
}
if protocol != arksdk.Rest && protocol != arksdk.Grpc {
return nil, errors.New("invalid protocol")
}
return &configStore{
aspUrl: aspUrl,
protocol: protocol,
}, nil
}
func (s *configStore) GetAspUrl(ctx context.Context) (string, error) {
return s.aspUrl, nil
}
func (s *configStore) GetAspPubKeyHex(ctx context.Context) (string, error) {
return s.aspPubKeyHex, nil
}
func (s *configStore) GetTransportProtocol(ctx context.Context) (arksdk.TransportProtocol, error) {
return s.protocol, nil
}
func (s *configStore) GetExplorerUrl(ctx context.Context) (string, error) {
return s.explorerUrl, nil
}
func (s *configStore) GetNetwork(ctx context.Context) (string, error) {
return s.net, nil
}
func (s *configStore) SetAspUrl(aspUrl string) {
s.aspUrl = aspUrl
}
func (s *configStore) SetAspPubKeyHex(aspPubKeyHex string) {
s.aspPubKeyHex = aspPubKeyHex
}
func (s *configStore) SetTransportProtocol(protocol arksdk.TransportProtocol) {
s.protocol = protocol
}
func (s *configStore) SetExplorerUrl(explorerUrl string) {
s.explorerUrl = explorerUrl
}
func (s *configStore) SetNetwork(net string) {
s.net = net
}
func (s *configStore) Save(ctx context.Context) error {
return nil // Implement save logic if needed
}

Some files were not shown because too many files have changed in this diff Show More