forked from xuperchain/burrow
/
dump_state.go
44 lines (38 loc) · 951 Bytes
/
dump_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package acmstate
import (
"bytes"
"encoding/hex"
"encoding/json"
"github.com/hyperledger/burrow/acm"
"github.com/hyperledger/burrow/binary"
"github.com/hyperledger/burrow/crypto"
)
type DumpState struct {
bytes.Buffer
}
func (dw *DumpState) UpdateAccount(updatedAccount *acm.Account) error {
dw.WriteString("UpdateAccount\n")
bs, err := json.Marshal(updatedAccount)
if err != nil {
return err
}
dw.Write(bs)
dw.WriteByte('\n')
return nil
}
func (dw *DumpState) RemoveAccount(address crypto.Address) error {
dw.WriteString("RemoveAccount\n")
dw.WriteString(address.String())
dw.WriteByte('\n')
return nil
}
func (dw *DumpState) SetStorage(address crypto.Address, key, value binary.Word256) error {
dw.WriteString("SetStorage\n")
dw.WriteString(address.String())
dw.WriteByte('/')
dw.WriteString(hex.EncodeToString(key[:]))
dw.WriteByte('/')
dw.WriteString(hex.EncodeToString(value[:]))
dw.WriteByte('\n')
return nil
}