MCPcopy Create free account
hub / github.com/chain/txvm / Bytes

Method Bytes

protocol/bc/block.go:170–196  ·  view source on GitHub ↗

Bytes encodes the Block as a byte slice, by converting it to a RawBlock protobuf and marshaling that.

()

Source from the content-addressed store, hash-verified

168// Bytes encodes the Block as a byte slice, by converting it to a
169// RawBlock protobuf and marshaling that.
170func (b *Block) Bytes() ([]byte, error) {
171 var txs []*RawTx
172 for _, tx := range b.Transactions {
173 txs = append(txs, &RawTx{
174 Version: tx.Version,
175 Runlimit: tx.Runlimit,
176 Program: tx.Program,
177 })
178 }
179 var args []*DataItem
180 for _, arg := range b.Arguments {
181 switch a := arg.(type) {
182 case []byte:
183 args = append(args, &DataItem{Type: DataType_BYTES, Bytes: a})
184 case int64:
185 args = append(args, &DataItem{Type: DataType_INT, Int: a})
186 case []*DataItem:
187 args = append(args, &DataItem{Type: DataType_TUPLE, Tuple: a})
188 }
189 }
190 rb := &RawBlock{
191 Header: b.BlockHeader,
192 Transactions: txs,
193 Arguments: args,
194 }
195 return proto.Marshal(rb)
196}

Callers 3

MarshalTextMethod · 0.95
ValueMethod · 0.95
buildFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected