Files
zeekay 6439541c91 Prove the two backends agree, on bytes neither of them wrote
Generating C++ is a claim. This runs it.

Both probes build the same cases from the same inputs — every type the dialect
has, plus the request and response envelopes the generated client and dispatch
produce — and print the hex; the two outputs are the same file. Then each
probe reads both probes' bytes with its own generated accessors, four
crossings, all agreeing. Then both read a corpus of real P-chain transactions
produced by the Go chain implementation, 134 vectors of which 44 are truncated
or malformed on purpose, and answer the same fields in the same places.

Neither probe decides anything: every value printed comes from a generated
accessor or a generated builder, so a disagreement between the probes is a
disagreement between the backends and nowhere else.

It earned its keep immediately. Five corpus vectors separated a Go [N]byte
accessor answering zeros from a C++ span answering empty, and the round trip
found the zero Object panicking in the Go runtime where C++ answered zero.
Both are fixed; neither was visible by reading.

list<T> carries a pointer and a count and nothing about elements — the dialect
cannot state a stride — so both languages agree on the count, which is all
either can say. That gap is in the dialect, in both backends at once.
2026-09-06 08:35:14 -07:00

91 lines
2.6 KiB
Go

// Code generated by zapgen; DO NOT EDIT.
// source: pchain.zap
package pchain
import (
zap "github.com/zap-proto/go"
)
const (
spendKindOff = 0
spendNetworkIDOff = 1
spendBlockchainIDOff = 5
spendOutsOff = 37
spendOwnerAddrsOff = 45
spendInsOff = 53
spendSigIndicesOff = 61
spendMemoOff = 69
spendSize = 77
)
// Spend is a zero-copy view into a ZAP-encoded Spend message.
type Spend struct{ o zap.Object }
// WrapSpend parses b and returns a typed view. Returns an error if the
// wire-level checks (magic, version, size) fail.
func WrapSpend(b []byte) (Spend, error) {
m, err := zap.Parse(b)
if err != nil {
return Spend{}, err
}
return Spend{o: m.Root()}, nil
}
func (t Spend) Kind() uint8 { return t.o.Uint8(spendKindOff) }
func (t Spend) NetworkID() uint32 { return t.o.Uint32(spendNetworkIDOff) }
func (t Spend) BlockchainID() [32]byte {
var out [32]byte
copy(out[:], t.o.BytesFixed(spendBlockchainIDOff, 32))
return out
}
func (t Spend) Outs() zap.List { return t.o.List(spendOutsOff) }
func (t Spend) OwnerAddrs() zap.List { return t.o.List(spendOwnerAddrsOff) }
func (t Spend) Ins() zap.List { return t.o.List(spendInsOff) }
func (t Spend) SigIndices() zap.List { return t.o.List(spendSigIndicesOff) }
func (t Spend) Memo() []byte { return t.o.Bytes(spendMemoOff) }
// SpendInput collects the field values for NewSpend.
type SpendInput struct {
Kind uint8
NetworkID uint32
BlockchainID [32]byte
Outs [][]byte
OwnerAddrs [][]byte
Ins [][]byte
SigIndices [][]byte
Memo []byte
}
// NewSpend builds a ZAP-encoded Spend message from in and returns the bytes.
func NewSpend(in SpendInput) []byte {
b := zap.NewBuilder(256)
ob := b.StartObject(spendSize)
ob.SetUint8(spendKindOff, in.Kind)
ob.SetUint32(spendNetworkIDOff, in.NetworkID)
ob.SetBytesFixed(spendBlockchainIDOff, in.BlockchainID[:])
outsLB := b.StartList(0)
for _, elem := range in.Outs {
outsLB.AddObjectBytes(elem)
}
ob.SetList(spendOutsOff, outsLB.FinishOffset(), len(in.Outs))
ownerAddrsLB := b.StartList(0)
for _, elem := range in.OwnerAddrs {
ownerAddrsLB.AddObjectBytes(elem)
}
ob.SetList(spendOwnerAddrsOff, ownerAddrsLB.FinishOffset(), len(in.OwnerAddrs))
insLB := b.StartList(0)
for _, elem := range in.Ins {
insLB.AddObjectBytes(elem)
}
ob.SetList(spendInsOff, insLB.FinishOffset(), len(in.Ins))
sigIndicesLB := b.StartList(0)
for _, elem := range in.SigIndices {
sigIndicesLB.AddObjectBytes(elem)
}
ob.SetList(spendSigIndicesOff, sigIndicesLB.FinishOffset(), len(in.SigIndices))
ob.SetBytes(spendMemoOff, in.Memo)
ob.FinishAsRoot()
return b.Finish()
}