Write dispatcher, change SetOption arguments
This commit is contained in:
@@ -80,8 +80,11 @@ func (h Handler) DeliverTx(ctx basecoin.Context, store types.KVStore, tx basecoi
|
||||
return basecoin.Result{}, nil
|
||||
}
|
||||
|
||||
func (h Handler) SetOption(l log.Logger, store types.KVStore, key, value string) (log string, err error) {
|
||||
if key == "base/account" {
|
||||
func (h Handler) SetOption(l log.Logger, store types.KVStore, module, key, value string) (log string, err error) {
|
||||
if module != NameCoin {
|
||||
return "", errors.ErrUnknownModule(module)
|
||||
}
|
||||
if key == "account" {
|
||||
var acc GenesisAccount
|
||||
err = data.FromJSON([]byte(value), &acc)
|
||||
if err != nil {
|
||||
|
||||
@@ -172,8 +172,7 @@ func TestSetOption(t *testing.T) {
|
||||
// some sample settings
|
||||
pk := crypto.GenPrivKeySecp256k1().Wrap()
|
||||
addr := pk.PubKey().Address()
|
||||
actor := basecoin.Actor{App: "coin", Address: addr}
|
||||
// actor2 := basecoin.Actor{App: "foo", Address: addr}
|
||||
actor := basecoin.Actor{App: stack.NameSigs, Address: addr}
|
||||
|
||||
someCoins := types.Coins{{"atom", 123}}
|
||||
otherCoins := types.Coins{{"eth", 11}}
|
||||
@@ -198,13 +197,13 @@ func TestSetOption(t *testing.T) {
|
||||
l := log.NewNopLogger()
|
||||
for i, tc := range cases {
|
||||
store := types.NewMemKVStore()
|
||||
key := "base/account"
|
||||
key := "account"
|
||||
|
||||
// set the options
|
||||
for j, gen := range tc.init {
|
||||
value, err := json.Marshal(gen)
|
||||
require.Nil(err, "%d,%d: %+v", i, j, err)
|
||||
_, err = h.SetOption(l, store, key, string(value))
|
||||
_, err = h.SetOption(l, store, NameCoin, key, string(value))
|
||||
require.Nil(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ type Account struct {
|
||||
}
|
||||
|
||||
func loadAccount(store types.KVStore, key []byte) (acct Account, err error) {
|
||||
// fmt.Printf("load: %X\n", key)
|
||||
data := store.Get(key)
|
||||
if len(data) == 0 {
|
||||
return acct, ErrNoAccount()
|
||||
@@ -107,6 +108,7 @@ func loadAccount(store types.KVStore, key []byte) (acct Account, err error) {
|
||||
}
|
||||
|
||||
func storeAccount(store types.KVStore, key []byte, acct Account) error {
|
||||
// fmt.Printf("store: %X\n", key)
|
||||
bin := wire.BinaryBytes(acct)
|
||||
store.Set(key, bin)
|
||||
return nil // real stores can return error...
|
||||
|
||||
Reference in New Issue
Block a user