mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 04:34:19 +01:00
* fix and test cheating scenario (malicious double spend) * test and fix async vtxo cheating cases * add replace statement in go.mod * Update server/internal/core/application/covenantless.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * Update server/internal/infrastructure/wallet/btc-embedded/psbt.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * Update server/test/e2e/covenant/e2e_test.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * Update server/test/e2e/covenantless/e2e_test.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * Update server/test/e2e/covenantless/e2e_test.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * remove unused * [btc-embedded] fix GetNotificationChannel * [tx-builder] fix redeem transaction fee estimator * close grpc client in tests * [application] rework listentoscannerNotification * [application][covenant] fix getConnectorAmount * [tx-builder][covenant] get connector amount from wallet * e2e test sleep time * [liquid-standalone] ListConnectorUtxos: filter by script client side * fix Makefile integrationtest * do not use cache in integration tests * use VtxoKey as argument of findForfeitTxBitcoin * wrap adversarial test in t.Run * increaste test timeout * CI: setup go 1.23.1 * CI: revert go version * add replace in server/go.mod * Update server/internal/core/application/covenant.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> * remove replace * readd replace statement * fixes * go work sync * fix CI --------- Signed-off-by: Louis Singer <41042567+louisinger@users.noreply.github.com> Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
127 lines
3.3 KiB
Go
127 lines
3.3 KiB
Go
package oceanwallet
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
|
|
pb "github.com/ark-network/ark/api-spec/protobuf/gen/ocean/v1"
|
|
"github.com/ark-network/ark/server/internal/core/ports"
|
|
"github.com/vulpemventures/go-elements/address"
|
|
"github.com/vulpemventures/go-elements/network"
|
|
)
|
|
|
|
func (s *service) DeriveAddresses(
|
|
ctx context.Context, numOfAddresses int,
|
|
) ([]string, error) {
|
|
return s.deriveAddresses(ctx, numOfAddresses, arkAccount)
|
|
}
|
|
|
|
func (s *service) DeriveConnectorAddress(ctx context.Context) (string, error) {
|
|
addresses, err := s.deriveAddresses(ctx, 1, connectorAccount)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return addresses[0], nil
|
|
}
|
|
|
|
func (s *service) ListConnectorUtxos(
|
|
ctx context.Context, connectorAddress string,
|
|
) ([]ports.TxInput, error) {
|
|
connectorScript, err := address.ToOutputScript(connectorAddress)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res, err := s.accountClient.ListUtxos(ctx, &pb.ListUtxosRequest{
|
|
AccountName: connectorAccount,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
utxos := make([]ports.TxInput, 0)
|
|
connectorScriptHex := hex.EncodeToString(connectorScript)
|
|
|
|
for _, utxo := range res.GetSpendableUtxos().GetUtxos() {
|
|
if utxo.Script != connectorScriptHex {
|
|
continue
|
|
}
|
|
|
|
utxos = append(utxos, utxo)
|
|
}
|
|
|
|
return utxos, nil
|
|
}
|
|
|
|
func (s *service) ConnectorsAccountBalance(ctx context.Context) (uint64, uint64, error) {
|
|
return s.getBalance(ctx, connectorAccount)
|
|
}
|
|
|
|
func (s *service) MainAccountBalance(ctx context.Context) (uint64, uint64, error) {
|
|
return s.getBalance(ctx, arkAccount)
|
|
}
|
|
|
|
func (s *service) getBalance(ctx context.Context, accountName string) (uint64, uint64, error) {
|
|
res, err := s.accountClient.Balance(ctx, &pb.BalanceRequest{
|
|
AccountName: accountName,
|
|
})
|
|
if err != nil {
|
|
return 0, 0, err
|
|
}
|
|
|
|
balances := res.GetBalance()
|
|
available, locked := getLBTCbalance(balances)
|
|
return available, locked, nil
|
|
}
|
|
|
|
func (s *service) deriveAddresses(
|
|
ctx context.Context, numOfAddresses int, account string,
|
|
) ([]string, error) {
|
|
res, err := s.accountClient.DeriveAddresses(ctx, &pb.DeriveAddressesRequest{
|
|
AccountName: account,
|
|
NumOfAddresses: uint64(numOfAddresses),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
addresses := make([]string, 0, numOfAddresses)
|
|
for _, addr := range res.GetAddresses() {
|
|
if isConf, _ := address.IsConfidential(addr); !isConf {
|
|
addresses = append(addresses, addr)
|
|
continue
|
|
}
|
|
info, _ := address.FromConfidential(addr)
|
|
addresses = append(addresses, info.Address)
|
|
}
|
|
return addresses, nil
|
|
}
|
|
|
|
func getLBTCbalance(balances map[string]*pb.BalanceInfo) (uint64, uint64) {
|
|
liquidBalance, liquidLockedBalance, found := getBalance(balances, network.Liquid.AssetID)
|
|
if found {
|
|
return liquidBalance, liquidLockedBalance
|
|
}
|
|
|
|
testnetBalance, testnetLockedBalance, found := getBalance(balances, network.Testnet.AssetID)
|
|
if found {
|
|
return testnetBalance, testnetLockedBalance
|
|
}
|
|
|
|
regtestBalance, regtestLockedBalance, found := getBalance(balances, network.Regtest.AssetID)
|
|
if found {
|
|
return regtestBalance, regtestLockedBalance
|
|
}
|
|
|
|
return 0, 0
|
|
}
|
|
|
|
func getBalance(balances map[string]*pb.BalanceInfo, assetID string) (uint64, uint64, bool) {
|
|
balance, ok := balances[assetID]
|
|
if !ok {
|
|
return 0, 0, false
|
|
}
|
|
|
|
return balance.GetConfirmedBalance() + balance.GetUnconfirmedBalance(), balance.GetLockedBalance(), true
|
|
}
|