Files
ark/noah/client.go
Pietralberto Mazza 3985bd4e14 Cleanup & Add config and launcher (#57)
* Fixes

* Fixes to domain layer:
* Add Leaf bool field to know to fix the returned list of leaves
* Add non-persisted UnsignedForfeitTxs to RoundFinalizationStarted
* Store only error msg when round fails instead of full error

* Fix wallet interface:
* Add Close() to close conn with wallet
* Add GetAsset() to fix missing asset err when calling Transfer()

* Fix gocron scheduler to correctly run/build the project

* Fix badger repo implementation:
* Fix datadirs of projection stores
* Return error if current round not found
* Fix round event deserialization

* Fix TxBuilder interface & dummy impl:
* Pass asp pubkey as arg of the defined functions
* Fix connectorsToInputArgs to return the right number of ins
* Fix getTxid() to return the id of an hex encoded tx too
* Fix createConnectors() to return a tx if there's only 1 connector
* Add leaf bool field to psetWithLevel in case a leaf is not in the last level
* Fix node's isLeaf() check
* Move to hex encoded pubkeys instead of ark encoded

* Fix app layer:
* Add Start() and Stop() to the interface & Expect raw pubkeys instead of strings as args
* Source & cache pubkey from wallet at startup
* Drop usage of scheduler and schedule next task based on occurred round events
* Increase verbosity
* Use hex instead of ark encoding to store receveirs' pubkeys
* Lower faucet amount from 100k to 10k sats in total
* Fix finalizeRound() to persist round events even if it failed
* Add view() to forfeitTxMap to enrich RoundFinalizationEvent with unsigned forfeit txs

* Add app config

* Fix interface layer:
* Remove repo manager from handler factory
* Fix GetEventStream to forward events to stream once they arrive from app layer
* Return missing unsigned forfeit txs in RoundFinalizationEvent
* Fix extracting user pubkey from address
* Add log interceptors
* Add config struct
* Add factory
* Clean interface

* Add config and launcher

* Tidy deps & Set defaut round interval to 30secs for dev mode
2023-12-12 14:55:22 +01:00

81 lines
1.6 KiB
Go

package main
import (
"fmt"
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/insecure"
)
type vtxo struct {
amount uint64
txid string
vout uint32
}
func getVtxos(ctx *cli.Context, client arkv1.ArkServiceClient) ([]vtxo, error) {
addr, err := getAddress()
if err != nil {
return nil, err
}
response, err := client.ListVtxos(ctx.Context, &arkv1.ListVtxosRequest{
Address: addr,
})
if err != nil {
return nil, err
}
vtxos := make([]vtxo, 0, len(response.Vtxos))
for _, v := range response.Vtxos {
vtxos = append(vtxos, vtxo{
amount: v.Receiver.Amount,
txid: v.Outpoint.Txid,
vout: v.Outpoint.Vout,
})
}
return vtxos, nil
}
// get the ark client and a function closing the connection
func getArkClient(ctx *cli.Context) (arkv1.ArkServiceClient, func(), error) {
conn, err := getConn(ctx)
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
}
// connect to the ark rpc URL specified in the config
func getConn(ctx *cli.Context) (*grpc.ClientConn, error) {
state, err := getState()
if err != nil {
return nil, err
}
rpcUrl, ok := state["ark_url"]
if !ok {
return nil, fmt.Errorf("missing ark_url")
}
conn, err := grpc.Dial(rpcUrl, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return nil, err
}
return conn, nil
}