mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 12:14:21 +01:00
* migrate descriptors --> tapscripts * fix covenantless * dynamic boarding exit delay * remove duplicates in tree and bitcointree * agnostic signatures validation * revert GetInfo change * renaming VtxoScript var * Agnostic script server (#6) * Hotfix: Prevent ZMQ-based bitcoin wallet to panic (#383) * Hotfix bct embedded wallet w/ ZMQ * Fixes * Rename vtxo is_oor to is_pending (#385) * Rename vtxo is_oor > is_pending * Clean swaggers * Revert changes to client and sdk * descriptor in oneof * support CHECKSIG_ADD in MultisigClosure * use right witness size in OOR tx fee estimation * Revert changes --------- Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package common
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
|
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
|
)
|
|
|
|
var (
|
|
ErrWrongDescriptor = errors.New("wrong descriptor, cannot parse vtxo script")
|
|
)
|
|
|
|
type TaprootMerkleProof struct {
|
|
ControlBlock []byte
|
|
Script []byte
|
|
WitnessSize int
|
|
}
|
|
|
|
// TaprootTree is an interface wrapping the methods needed to spend a vtxo taproot contract
|
|
// the implementation depends on the chain (liquid or bitcoin)
|
|
type TaprootTree interface {
|
|
GetLeaves() []chainhash.Hash
|
|
GetTaprootMerkleProof(leafhash chainhash.Hash) (*TaprootMerkleProof, error)
|
|
GetRoot() chainhash.Hash
|
|
}
|
|
|
|
/*
|
|
A vtxo script is defined as a taproot contract with at least 1 forfeit closure (User && ASP) and 1 exit closure (A after t).
|
|
It may also contain others closures implementing specific use cases.
|
|
|
|
VtxoScript abstracts the taproot complexity behind vtxo contracts.
|
|
it is compiled, transferred and parsed using descriptor string.
|
|
*/
|
|
type VtxoScript[T TaprootTree, F interface{}, E interface{}] interface {
|
|
Validate(server *secp256k1.PublicKey, minExitDelay uint) error
|
|
TapTree() (taprootKey *secp256k1.PublicKey, taprootScriptTree T, err error)
|
|
Encode() ([]string, error)
|
|
Decode(scripts []string) error
|
|
SmallestExitDelay() (uint, error)
|
|
ForfeitClosures() []F
|
|
ExitClosures() []E
|
|
}
|
|
|
|
// BiggestLeafMerkleProof returns the leaf with the biggest witness size (for fee estimation)
|
|
// we need this to estimate the fee without knowning the exact leaf that will be spent
|
|
func BiggestLeafMerkleProof(t TaprootTree) (*TaprootMerkleProof, error) {
|
|
var biggest *TaprootMerkleProof
|
|
var biggestSize int
|
|
|
|
for _, leaf := range t.GetLeaves() {
|
|
proof, err := t.GetTaprootMerkleProof(leaf)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if len(proof.ControlBlock)+len(proof.Script) > biggestSize {
|
|
biggest = proof
|
|
biggestSize = len(proof.ControlBlock) + len(proof.Script)
|
|
}
|
|
}
|
|
|
|
return biggest, nil
|
|
}
|