OSDN Git Service

add block witness update function (#176)
[bytom/vapor.git] / protocol / bc / types / block_witness.go
index e4bb2ac..52f3e0e 100644 (file)
@@ -20,3 +20,25 @@ func (bw *BlockWitness) readFrom(r *blockchain.Reader) (err error) {
        bw.Witness, err = blockchain.ReadVarstrList(r)
        return err
 }
        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
+}