From 8ee754aedbb6cfa8fe7892592bc15ee46f76d800 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 01:58:27 +0000 Subject: [PATCH] Add bid covenant builder --- pkg/primitives/covenant_items.go | 11 +++++++ pkg/primitives/covenant_items_test.go | 42 +++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/pkg/primitives/covenant_items.go b/pkg/primitives/covenant_items.go index cef6bb5..6ffeb39 100644 --- a/pkg/primitives/covenant_items.go +++ b/pkg/primitives/covenant_items.go @@ -137,6 +137,17 @@ func (c *Covenant) SetOpen(nameHash Hash, rawName []byte) *Covenant { return c } +// SetBid configures the covenant as a BID operation. +func (c *Covenant) SetBid(nameHash Hash, height uint32, rawName []byte, blind Hash) *Covenant { + c.Type = covenantTypeBid + c.Items = nil + c.PushHash(nameHash) + c.PushU32(height) + c.Push(rawName) + c.PushHash(blind) + return c +} + // GetU8 returns the item at the requested index as a uint8. func (c Covenant) GetU8(index int) (uint8, error) { item, err := c.Get(index) diff --git a/pkg/primitives/covenant_items_test.go b/pkg/primitives/covenant_items_test.go index fc02c4d..f1a2dbe 100644 --- a/pkg/primitives/covenant_items_test.go +++ b/pkg/primitives/covenant_items_test.go @@ -98,6 +98,48 @@ func TestCovenantItemHelpers(t *testing.T) { t.Fatalf("SetOpen() GetString() = %q, want %q", str, "bar") } + cov.SetBid(Hash{4, 5, 6}, 42, []byte("baz"), Hash{7, 8, 9}) + + if got := cov.Type; got != covenantTypeBid { + t.Fatalf("SetBid() set type %d, want %d", got, covenantTypeBid) + } + + if got := cov.Len(); got != 4 { + t.Fatalf("SetBid() len = %d, want 4", got) + } + + hash, err = cov.GetHash(0) + if err != nil { + t.Fatalf("SetBid() GetHash returned error: %v", err) + } + if hash[0] != 4 || hash[1] != 5 || hash[2] != 6 { + t.Fatalf("SetBid() hash = %x, want 040506...", hash[:3]) + } + + height, err = cov.GetU32(1) + if err != nil { + t.Fatalf("SetBid() GetU32 returned error: %v", err) + } + if height != 42 { + t.Fatalf("SetBid() height = %d, want 42", height) + } + + str, err = cov.GetString(2) + if err != nil { + t.Fatalf("SetBid() GetString returned error: %v", err) + } + if str != "baz" { + t.Fatalf("SetBid() GetString() = %q, want %q", str, "baz") + } + + blind, err := cov.GetHash(3) + if err != nil { + t.Fatalf("SetBid() GetHash(3) returned error: %v", err) + } + if blind[0] != 7 || blind[1] != 8 || blind[2] != 9 { + t.Fatalf("SetBid() blind = %x, want 070809...", blind[:3]) + } + cov = Covenant{} cov.PushU8(7). PushU32(0x11223344).