github.com/sixexorg/magnetic-ring@v0.0.0-20191119090307-31705a21e419/store/orgchain/vm_storages/variable_store.go (about) 1 package vm_storages 2 3 import ( 4 "github.com/sixexorg/magnetic-ring/common" 5 "github.com/sixexorg/magnetic-ring/store/db" 6 "github.com/sixexorg/magnetic-ring/vm/cvm" 7 ) 8 9 type LValueStore struct { 10 dbDir string 11 store *db.LevelDBStore 12 } 13 14 func NewLValueStore() (*LValueStore, error) { 15 var err error 16 store, err := db.NewLevelDBStore("") 17 if err != nil { 18 return nil, err 19 } 20 lValueStore := &LValueStore{ 21 dbDir: "", 22 store: store, 23 } 24 return lValueStore, nil 25 } 26 27 func (this *LValueStore) Save(lv cvm.LValue, address common.Address) error { 28 data := cvm.LVSerialize(lv) 29 return this.store.Put(address[:], data) 30 } 31 32 func (this *LValueStore) Get(address common.Address) (cvm.LValue, error) { 33 data, err := this.store.Get(address[:]) 34 if err != nil { 35 return nil, err 36 } 37 return cvm.LVDeserialize(data), nil 38 }