New address encoding (#356)

* [common] rework address encoding

* new address encoding

* replace offchain address by vtxo output key in DB

* merge migrations files into init one

* fix txbuilder fixtures

* fix transaction events
This commit is contained in:
Louis Singer
2024-10-18 16:50:07 +02:00
committed by GitHub
parent b1c9261f14
commit b536a9e652
58 changed files with 2243 additions and 1896 deletions

View File

@@ -68,9 +68,12 @@ func (p Payment) validate(ignoreOuts bool) error {
return fmt.Errorf("missing outputs")
}
for _, r := range p.Receivers {
if len(r.OnchainAddress) <= 0 && len(r.Descriptor) <= 0 {
if len(r.OnchainAddress) <= 0 && len(r.Pubkey) <= 0 {
return fmt.Errorf("missing receiver destination")
}
if r.Amount == 0 {
return fmt.Errorf("missing receiver amount")
}
}
return nil
}
@@ -80,6 +83,10 @@ type VtxoKey struct {
VOut uint32
}
func (k VtxoKey) String() string {
return fmt.Sprintf("%s:%d", k.Txid, k.VOut)
}
func (k VtxoKey) Hash() string {
calcHash := func(buf []byte, hasher hash.Hash) []byte {
_, _ = hasher.Write(buf)
@@ -96,9 +103,9 @@ func (k VtxoKey) Hash() string {
}
type Receiver struct {
Descriptor string
Amount uint64
OnchainAddress string
OnchainAddress string // onchain
Pubkey string // offchain
}
func (r Receiver) IsOnchain() bool {
@@ -107,7 +114,8 @@ func (r Receiver) IsOnchain() bool {
type Vtxo struct {
VtxoKey
Receiver
Amount uint64
Pubkey string
RoundTxid string
SpentBy string // round txid or async redeem txid
Spent bool