Files
ark/pkg/client-sdk/client/client.go
Pietralberto Mazza 8de2df3d7f Covenant-less ark sdk (#225)
* Add method to compute vtxo taproot script

* Drop debug logs

* Refactor client:
* Remove dep from stubs in interface
* Remove redeem branch, out of scope (moved to ark client)

* Add example for covenant and covenantless sdk

* Simplify explorer - No need for bitcoin and liquid impls

* Refactor wallet:
* wallet struct for common operations (create, lock/unlock, getType, isLocked)
* liquidWallet struct for liquid operations (derive/get addresses, sign tx)
* bitcoinWallet struct for bitcoin operations (derive/get addresses, sign tx)

* Update utils:
* drop methods to parse tree (moved to ark client)
* add methods for encryption, network parsing, key generation
* add methods for covenant/covenantless redeem branches (move to common?)

* Add support for covenantless sdk:
* move interface to dedicated file
* arkCLient struct for common operations (Init, lock/unlock, get config data, receive)
* covenantArkClient struct for covenant operations (onboard, balance, send, redeem)
* covenantlessArkClient struct for covenantless operations (onboard, balance, send, redeem)

* Fix wasm

* Fixes

* Make explorer use utils.Cache

* Renamings

* Lint

* Fix e2e tests

* Fix e2e test
2024-08-07 01:37:18 +02:00

133 lines
2.5 KiB
Go

package client
import (
"context"
"time"
"github.com/ark-network/ark/common/tree"
)
const (
GrpcClient = "grpc"
RestClient = "rest"
)
type RoundEvent interface {
isRoundEvent()
}
type ASPClient interface {
GetInfo(ctx context.Context) (*Info, error)
ListVtxos(ctx context.Context, addr string) ([]Vtxo, []Vtxo, error)
GetRound(ctx context.Context, txID string) (*Round, error)
GetRoundByID(ctx context.Context, roundID string) (*Round, error)
Onboard(
ctx context.Context, tx, userPubkey string, congestionTree tree.CongestionTree,
) error
RegisterPayment(
ctx context.Context, inputs []VtxoKey,
) (string, error)
ClaimPayment(
ctx context.Context, paymentID string, outputs []Output,
) error
GetEventStream(
ctx context.Context, paymentID string,
) (<-chan RoundEventChannel, error)
Ping(ctx context.Context, paymentID string) (*RoundFinalizationEvent, error)
FinalizePayment(
ctx context.Context, signedForfeitTxs []string,
) error
Close()
}
type Info struct {
Pubkey string
RoundLifetime int64
UnilateralExitDelay int64
RoundInterval int64
Network string
MinRelayFee int64
}
type RoundEventChannel struct {
Event RoundEvent
Err error
}
type VtxoKey struct {
Txid string
VOut uint32
}
type Vtxo struct {
VtxoKey
Amount uint64
RoundTxid string
ExpiresAt *time.Time
}
type Output struct {
Address string
Amount uint64
}
type RoundStage int
func (s RoundStage) String() string {
switch s {
case RoundStageRegistration:
return "ROUND_STAGE_REGISTRATION"
case RoundStageFinalization:
return "ROUND_STAGE_FINALIZATION"
case RoundStageFinalized:
return "ROUND_STAGE_FINALIZED"
case RoundStageFailed:
return "ROUND_STAGE_FAILED"
default:
return "ROUND_STAGE_UNDEFINED"
}
}
const (
RoundStageUndefined RoundStage = iota
RoundStageRegistration
RoundStageFinalization
RoundStageFinalized
RoundStageFailed
)
type Round struct {
ID string
StartedAt *time.Time
EndedAt *time.Time
Tx string
Tree tree.CongestionTree
ForfeitTxs []string
Connectors []string
Stage RoundStage
}
type RoundFinalizationEvent struct {
ID string
Tx string
ForfeitTxs []string
Tree tree.CongestionTree
Connectors []string
}
func (e RoundFinalizationEvent) isRoundEvent() {}
type RoundFinalizedEvent struct {
ID string
Txid string
}
func (e RoundFinalizedEvent) isRoundEvent() {}
type RoundFailedEvent struct {
ID string
Reason string
}
func (e RoundFailedEvent) isRoundEvent() {}