mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 04:04:21 +01:00
CLI with ARK Sdk (#307)
* Export new methods * Use sdk in CLI * pr review refactor * go sync * Fixes * run integration test on every change * fixes * go sync * fix * Persist explorer url * Fix decoding bitcoin address * Add missing timeout to e2e test * Fix * Fixes --------- Co-authored-by: altafan <18440657+altafan@users.noreply.github.com>
This commit is contained in:
@@ -12,7 +12,9 @@ import (
|
||||
"github.com/ark-network/ark/common"
|
||||
"github.com/ark-network/ark/pkg/client-sdk/client"
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/vulpemventures/go-elements/address"
|
||||
"github.com/vulpemventures/go-elements/network"
|
||||
@@ -63,7 +65,7 @@ func CoinSelect(
|
||||
return selected, change, nil
|
||||
}
|
||||
|
||||
func DecodeReceiverAddress(addr string) (
|
||||
func ParseLiquidAddress(addr string) (
|
||||
bool, []byte, *secp256k1.PublicKey, error,
|
||||
) {
|
||||
outputScript, err := address.ToOutputScript(addr)
|
||||
@@ -78,9 +80,43 @@ func DecodeReceiverAddress(addr string) (
|
||||
return true, outputScript, nil, nil
|
||||
}
|
||||
|
||||
func IsOnchainOnly(receivers []client.Output) bool {
|
||||
func ParseBitcoinAddress(addr string, net chaincfg.Params) (
|
||||
bool, []byte, *secp256k1.PublicKey, error,
|
||||
) {
|
||||
btcAddr, err := btcutil.DecodeAddress(addr, &net)
|
||||
if err != nil {
|
||||
_, userPubkey, _, err := common.DecodeAddress(addr)
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
return false, nil, userPubkey, nil
|
||||
}
|
||||
|
||||
onchainScript, err := txscript.PayToAddrScript(btcAddr)
|
||||
if err != nil {
|
||||
return false, nil, nil, err
|
||||
}
|
||||
return true, onchainScript, nil, nil
|
||||
}
|
||||
|
||||
func IsBitcoinOnchainOnly(receivers []client.Output, net chaincfg.Params) bool {
|
||||
for _, receiver := range receivers {
|
||||
isOnChain, _, _, err := DecodeReceiverAddress(receiver.Address)
|
||||
isOnChain, _, _, err := ParseBitcoinAddress(receiver.Address, net)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if !isOnChain {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func IsLiquidOnchainOnly(receivers []client.Output) bool {
|
||||
for _, receiver := range receivers {
|
||||
isOnChain, _, _, err := ParseLiquidAddress(receiver.Address)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user