forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
115 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package state | ||
|
||
import ( | ||
"github.com/tendermint/basecoin/types" | ||
"sort" | ||
) | ||
|
||
type AccountCache struct { | ||
state *State | ||
accounts map[string]*types.Account | ||
} | ||
|
||
func NewAccountCache(state *State) *AccountCache { | ||
return &AccountCache{ | ||
state: state, | ||
accounts: make(map[string]*types.Account), | ||
} | ||
} | ||
|
||
func (cache *AccountCache) GetAccount(addr []byte) *types.Account { | ||
acc, ok := cache.accounts[string(addr)] | ||
if !ok { | ||
acc = cache.state.GetAccount(addr) | ||
cache.accounts[string(addr)] = acc | ||
} | ||
return acc | ||
} | ||
|
||
func (cache *AccountCache) SetAccount(addr []byte, acc *types.Account) { | ||
cache.accounts[string(addr)] = acc | ||
} | ||
|
||
func (cache *AccountCache) Sync() { | ||
// MUST BE DETERMINISTIC | ||
// First, order the addrs. | ||
addrs := []string{} | ||
for addr := range cache.accounts { | ||
addrs = append(addrs, string(addr)) | ||
} | ||
sort.Strings(addrs) | ||
|
||
// Set the accounts in order. | ||
for _, addr := range addrs { | ||
cache.state.SetAccount([]byte(addr), cache.accounts[addr]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package types | ||
|
||
import ( | ||
tmsp "github.com/tendermint/tmsp/types" | ||
) | ||
|
||
// Value is any floating value. It must be given to someone. | ||
// Gas is a pointer to remainig gas. Decrement as you go, | ||
// if any gas is left the user is | ||
type Plugin interface { | ||
CallTx(ctx CallContext, txBytes []byte) tmsp.Result | ||
} | ||
|
||
type CallContext struct { | ||
Cache AccountCacher | ||
Caller *Account | ||
Value int64 | ||
Gas *int64 | ||
} | ||
|
||
func NewCallContext(cache AccountCacher, caller *Account, value int64, gas *int64) CallContext { | ||
return CallContext{ | ||
Cache: cache, | ||
Caller: caller, | ||
Value: value, | ||
Gas: gas, | ||
} | ||
} |