mirror of
https://github.com/zap-proto/go.git
synced 2026-10-30 15:05:00 +00:00
Two things the X-chain's wire needs to be sayable. NFTMintOperation reserves 36 bytes for fields that end at 32. Emitting 32 puts the byte tail four bytes early and moves everything after it, so `struct Name @N` states the width the wire reserves. Narrower than the fields is a contradiction and is refused. `package lux.xvm.wire` is one path, rendered by each backend the way that language spells a namespace: C++ opens all of it, Go takes the last segment, which is what a Go package name is. Without it the generated header can only land at global scope, and a chain whose own wire namespace is three deep has to either move or alias — and an alias is a second name for one thing.
125 lines
3.5 KiB
Plaintext
125 lines
3.5 KiB
Plaintext
// Code generated by zapgen; DO NOT EDIT.
|
|
// source: basetx.zap
|
|
|
|
package xvm
|
|
|
|
import (
|
|
zap "github.com/zap-proto/go"
|
|
)
|
|
|
|
const (
|
|
baseTxNetworkIDOff = 0
|
|
baseTxBlockchainIDOff = 8
|
|
baseTxOutsOff = 40
|
|
baseTxInsOff = 48
|
|
baseTxMemoOff = 56
|
|
baseTxSize = 64
|
|
)
|
|
|
|
// BaseTx is a zero-copy view into a ZAP-encoded BaseTx message.
|
|
type BaseTx struct{ o zap.Object }
|
|
|
|
// WrapBaseTx parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapBaseTx(b []byte) (BaseTx, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return BaseTx{}, err
|
|
}
|
|
return BaseTx{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t BaseTx) NetworkID() uint32 { return t.o.Uint32(baseTxNetworkIDOff) }
|
|
func (t BaseTx) BlockchainID() [32]byte {
|
|
var out [32]byte
|
|
copy(out[:], t.o.BytesFixed(baseTxBlockchainIDOff, 32))
|
|
return out
|
|
}
|
|
func (t BaseTx) Outs() zap.List { return t.o.ListStride(baseTxOutsOff, 4) }
|
|
func (t BaseTx) OutsAt(i int) Transfer { return Transfer{o: t.Outs().ObjectPtr(i)} }
|
|
func (t BaseTx) Ins() zap.List { return t.o.ListStride(baseTxInsOff, 4) }
|
|
func (t BaseTx) InsAt(i int) Spend { return Spend{o: t.Ins().ObjectPtr(i)} }
|
|
func (t BaseTx) Memo() []byte { return t.o.Bytes(baseTxMemoOff) }
|
|
|
|
// BaseTxInput collects the field values for NewBaseTx.
|
|
type BaseTxInput struct {
|
|
NetworkID uint32
|
|
BlockchainID [32]byte
|
|
Outs []TransferInput
|
|
Ins []SpendInput
|
|
Memo []byte
|
|
}
|
|
|
|
// AppendBaseTx writes one BaseTx object into b — every payload it points at first,
|
|
// then the object itself — and returns the object's offset.
|
|
func AppendBaseTx(b *zap.Builder, in BaseTxInput) int {
|
|
outsPtrs := make([]int, 0, len(in.Outs))
|
|
for _, elem := range in.Outs {
|
|
outsPtrs = append(outsPtrs, AppendTransfer(b, elem))
|
|
}
|
|
insPtrs := make([]int, 0, len(in.Ins))
|
|
for _, elem := range in.Ins {
|
|
insPtrs = append(insPtrs, AppendSpend(b, elem))
|
|
}
|
|
outsOff := 0
|
|
if len(in.Outs) > 0 {
|
|
lb := b.StartList(4)
|
|
for _, at := range outsPtrs {
|
|
lb.AddObjectPtr(at)
|
|
}
|
|
outsOff = lb.FinishOffset()
|
|
}
|
|
insOff := 0
|
|
if len(in.Ins) > 0 {
|
|
lb := b.StartList(4)
|
|
for _, at := range insPtrs {
|
|
lb.AddObjectPtr(at)
|
|
}
|
|
insOff = lb.FinishOffset()
|
|
}
|
|
ob := b.StartObject(baseTxSize)
|
|
ob.SetUint32(baseTxNetworkIDOff, in.NetworkID)
|
|
ob.SetBytesFixed(baseTxBlockchainIDOff, in.BlockchainID[:])
|
|
ob.SetList(baseTxOutsOff, outsOff, len(in.Outs))
|
|
ob.SetList(baseTxInsOff, insOff, len(in.Ins))
|
|
ob.SetBytes(baseTxMemoOff, in.Memo)
|
|
return ob.Finish()
|
|
}
|
|
|
|
// NewBaseTx builds a ZAP-encoded BaseTx message from in and returns the bytes.
|
|
func NewBaseTx(in BaseTxInput) []byte {
|
|
b := zap.NewBuilderV2(256)
|
|
outsPtrs := make([]int, 0, len(in.Outs))
|
|
for _, elem := range in.Outs {
|
|
outsPtrs = append(outsPtrs, AppendTransfer(b, elem))
|
|
}
|
|
insPtrs := make([]int, 0, len(in.Ins))
|
|
for _, elem := range in.Ins {
|
|
insPtrs = append(insPtrs, AppendSpend(b, elem))
|
|
}
|
|
outsOff := 0
|
|
if len(in.Outs) > 0 {
|
|
lb := b.StartList(4)
|
|
for _, at := range outsPtrs {
|
|
lb.AddObjectPtr(at)
|
|
}
|
|
outsOff = lb.FinishOffset()
|
|
}
|
|
insOff := 0
|
|
if len(in.Ins) > 0 {
|
|
lb := b.StartList(4)
|
|
for _, at := range insPtrs {
|
|
lb.AddObjectPtr(at)
|
|
}
|
|
insOff = lb.FinishOffset()
|
|
}
|
|
ob := b.StartObject(baseTxSize)
|
|
ob.SetUint32(baseTxNetworkIDOff, in.NetworkID)
|
|
ob.SetBytesFixed(baseTxBlockchainIDOff, in.BlockchainID[:])
|
|
ob.SetList(baseTxOutsOff, outsOff, len(in.Outs))
|
|
ob.SetList(baseTxInsOff, insOff, len(in.Ins))
|
|
ob.SetBytes(baseTxMemoOff, in.Memo)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|