X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=protocol%2Fbc%2Ftypes%2Fblock_witness.go;h=52f3e0e4482adb6556828aea787573d2818572f8;hp=e4bb2ac7c600e6e618409a98db4e4363b2e6bd02;hb=f47413c46121216dae3b1a905fbe53ae559adee2;hpb=4cd4945c706817ae5b3dcd76d874a5072cfcc4c2 diff --git a/protocol/bc/types/block_witness.go b/protocol/bc/types/block_witness.go index e4bb2ac7..52f3e0e4 100644 --- a/protocol/bc/types/block_witness.go +++ b/protocol/bc/types/block_witness.go @@ -20,3 +20,25 @@ func (bw *BlockWitness) readFrom(r *blockchain.Reader) (err error) { bw.Witness, err = blockchain.ReadVarstrList(r) return err } + +func (bw *BlockWitness) Set(index uint64, data []byte) { + if uint64(len(bw.Witness)) <= index { + newWitness := make([][]byte, index+1, index+1) + copy(newWitness, bw.Witness) + bw.Witness = newWitness + } + bw.Witness[index] = data +} + +func (bw *BlockWitness) Delete(index uint64) { + if uint64(len(bw.Witness)) > index { + bw.Witness[index] = nil + } +} + +func (bw *BlockWitness) Get(index uint64) []byte { + if uint64(len(bw.Witness)) > index { + return bw.Witness[index] + } + return nil +}