diff --git a/consensus/tendermint/tendermint.go b/consensus/tendermint/tendermint.go index 9b80324206d1a3b6a10a5aa5ef530a62c1edf4a9..f48f7df77cbefa385bcd12a9035ad5658582ba55 100644 --- a/consensus/tendermint/tendermint.go +++ b/consensus/tendermint/tendermint.go @@ -30,6 +30,7 @@ import ( node "github.com/tendermint/tendermint/node" proxy "github.com/tendermint/tendermint/proxy" tendermint_types "github.com/tendermint/tendermint/types" + tmsp_types "github.com/tendermint/tmsp/types" log "github.com/eris-ltd/eris-logger" @@ -194,6 +195,11 @@ func (this *TendermintNode) PublicValidatorKey() crypto.PubKey { return copyPublicValidatorKey } +func (this *TendermintNode) BroadcastTransaction(transaction []byte, + callback func(*tmsp_types.Response)) error { + return this.tmintNode.MempoolReactor().BroadcastTx(transaction, callback) +} + //------------------------------------------------------------------------------ // Helper functions diff --git a/definitions/consensus.go b/definitions/consensus.go index 20735cb2e925d6091360eb7972082594d2fd7997..98e7ed86da4074356c28ed045198e035526ba487 100644 --- a/definitions/consensus.go +++ b/definitions/consensus.go @@ -20,6 +20,7 @@ import ( crypto "github.com/tendermint/go-crypto" p2p "github.com/tendermint/go-p2p" tendermint_types "github.com/tendermint/tendermint/types" + tmsp_types "github.com/tendermint/tmsp/types" rpc_tendermint_types "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" ) @@ -42,6 +43,10 @@ type ConsensusEngine interface { // Private Validator PublicValidatorKey() crypto.PubKey + // Memory pool + BroadcastTransaction(transaction []byte, + callback func(*tmsp_types.Response)) error + } // type Communicator interface { diff --git a/manager/eris-mint/pipe.go b/manager/eris-mint/pipe.go index 758320159efdf68ff98740d11bb78d155eaa0473..d1071584bc4a10a1bb901c46c4fcb0349f93c5c4 100644 --- a/manager/eris-mint/pipe.go +++ b/manager/eris-mint/pipe.go @@ -21,6 +21,7 @@ import ( "fmt" db "github.com/tendermint/go-db" + tendermint_common "github.com/tendermint/go-common" tendermint_events "github.com/tendermint/go-events" tendermint_types "github.com/tendermint/tendermint/types" wire "github.com/tendermint/go-wire" @@ -270,21 +271,63 @@ func (pipe *ErisMintPipe) Genesis() (*rpc_tendermint_types.ResultGenesis, error) // Accounts func (pipe *ErisMintPipe) GetAccount(address []byte) (*rpc_tendermint_types.ResultGetAccount, error) { - return nil, fmt.Errorf("Unimplemented.") + cache := pipe.erisMint.GetCheckCache() + // cache := mempoolReactor.Mempool.GetCache() + account := cache.GetAccount(address) + if account == nil { + log.Warn("Nil Account") + return &rpc_tendermint_types.ResultGetAccount{nil}, nil + } + return &rpc_tendermint_types.ResultGetAccount{account}, nil } func (pipe *ErisMintPipe) ListAccounts() (*rpc_tendermint_types.ResultListAccounts, error) { - return nil, fmt.Errorf("Unimplemented.") + var blockHeight int + var accounts []*account.Account + state := pipe.erisMint.GetState() + blockHeight = state.LastBlockHeight + state.GetAccounts().Iterate(func(key []byte, value []byte) bool { + accounts = append(accounts, account.DecodeAccount(value)) + return false + }) + return &rpc_tendermint_types.ResultListAccounts{blockHeight, accounts}, nil } func (pipe *ErisMintPipe) GetStorage(address, key []byte) (*rpc_tendermint_types.ResultGetStorage, error) { - return nil, fmt.Errorf("Unimplemented.") + state := pipe.erisMint.GetState() + // state := consensusState.GetState() + account := state.GetAccount(address) + if account == nil { + return nil, fmt.Errorf("UnknownAddress: %X", address) + } + storageRoot := account.StorageRoot + storageTree := state.LoadStorage(storageRoot) + + _, value, exists := storageTree.Get( + tendermint_common.LeftPadWord256(key).Bytes()) + if !exists { // value == nil { + return &rpc_tendermint_types.ResultGetStorage{key, nil}, nil + } + return &rpc_tendermint_types.ResultGetStorage{key, value}, nil } func (pipe *ErisMintPipe) DumpStorage(address []byte) (*rpc_tendermint_types.ResultDumpStorage, error) { - return nil, fmt.Errorf("Unimplemented.") + state := pipe.erisMint.GetState() + account := state.GetAccount(address) + if account == nil { + return nil, fmt.Errorf("UnknownAddress: %X", address) + } + storageRoot := account.StorageRoot + storageTree := state.LoadStorage(storageRoot) + storageItems := []rpc_tendermint_types.StorageItem{} + storageTree.Iterate(func(key []byte, value []byte) bool { + storageItems = append(storageItems, rpc_tendermint_types.StorageItem{key, + value}) + return false + }) + return &rpc_tendermint_types.ResultDumpStorage{storageRoot, storageItems}, nil } // Call @@ -317,9 +360,14 @@ func (pipe *ErisMintPipe) ListNames() (*rpc_tendermint_types.ResultListNames, er } // Memory pool -func (pipe *ErisMintPipe) BroadcastTxAsync(transaction transaction.Tx) (*rpc_tendermint_types.ResultBroadcastTx, - error) { - return nil, fmt.Errorf("Unimplemented.") +// NOTE: transaction must be signed +func (pipe *ErisMintPipe) BroadcastTxAsync(tx transaction.Tx) ( + *rpc_tendermint_types.ResultBroadcastTx, error) { + err := pipe.consensusEngine.BroadcastTransaction(transaction.EncodeTx(tx), nil) + if err != nil { + return nil, fmt.Errorf("Error broadcasting transaction: %v", err) + } + return &rpc_tendermint_types.ResultBroadcastTx{}, nil } func (pipe *ErisMintPipe) BroadcastTxSync(transaction transaction.Tx) (*rpc_tendermint_types.ResultBroadcastTx, diff --git a/rpc/tendermint/core/accounts.go b/rpc/tendermint/core/accounts.go deleted file mode 100644 index 86d99f8a5640d342ff1b8371536a87061fef52a3..0000000000000000000000000000000000000000 --- a/rpc/tendermint/core/accounts.go +++ /dev/null @@ -1,70 +0,0 @@ -package core - -import ( - "fmt" - - acm "github.com/eris-ltd/eris-db/account" - ctypes "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" - . "github.com/tendermint/go-common" -) - -func GenPrivAccount() (*ctypes.ResultGenPrivAccount, error) { - return &ctypes.ResultGenPrivAccount{acm.GenPrivAccount()}, nil -} - -// If the account is not known, returns nil, nil. -func GetAccount(address []byte) (*ctypes.ResultGetAccount, error) { - cache := erisMint.GetCheckCache() - // cache := mempoolReactor.Mempool.GetCache() - account := cache.GetAccount(address) - if account == nil { - log.Warn("Nil Account") - return &ctypes.ResultGetAccount{nil}, nil - } - return &ctypes.ResultGetAccount{account}, nil -} - -func GetStorage(address, key []byte) (*ctypes.ResultGetStorage, error) { - state := erisMint.GetState() - // state := consensusState.GetState() - account := state.GetAccount(address) - if account == nil { - return nil, fmt.Errorf("UnknownAddress: %X", address) - } - storageRoot := account.StorageRoot - storageTree := state.LoadStorage(storageRoot) - - _, value, exists := storageTree.Get(LeftPadWord256(key).Bytes()) - if !exists { // value == nil { - return &ctypes.ResultGetStorage{key, nil}, nil - } - return &ctypes.ResultGetStorage{key, value}, nil -} - -func ListAccounts() (*ctypes.ResultListAccounts, error) { - var blockHeight int - var accounts []*acm.Account - state := erisMint.GetState() - blockHeight = state.LastBlockHeight - state.GetAccounts().Iterate(func(key []byte, value []byte) bool { - accounts = append(accounts, acm.DecodeAccount(value)) - return false - }) - return &ctypes.ResultListAccounts{blockHeight, accounts}, nil -} - -func DumpStorage(address []byte) (*ctypes.ResultDumpStorage, error) { - state := erisMint.GetState() - account := state.GetAccount(address) - if account == nil { - return nil, fmt.Errorf("UnknownAddress: %X", address) - } - storageRoot := account.StorageRoot - storageTree := state.LoadStorage(storageRoot) - storageItems := []ctypes.StorageItem{} - storageTree.Iterate(func(key []byte, value []byte) bool { - storageItems = append(storageItems, ctypes.StorageItem{key, value}) - return false - }) - return &ctypes.ResultDumpStorage{storageRoot, storageItems}, nil -} diff --git a/rpc/tendermint/core/mempool.go b/rpc/tendermint/core/mempool.go index 78afb7121b410591928241a2442a839ff4a7c545..5e59667080aa411ca6f847a77d068f2a5708421f 100644 --- a/rpc/tendermint/core/mempool.go +++ b/rpc/tendermint/core/mempool.go @@ -5,20 +5,20 @@ import ( ctypes "github.com/eris-ltd/eris-db/rpc/tendermint/core/types" txs "github.com/eris-ltd/eris-db/txs" - "github.com/tendermint/tendermint/types" + // "github.com/tendermint/tendermint/types" tmsp "github.com/tendermint/tmsp/types" ) //----------------------------------------------------------------------------- -// NOTE: tx must be signed -func BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { - err := mempoolReactor.BroadcastTx(tx, nil) - if err != nil { - return nil, fmt.Errorf("Error broadcasting transaction: %v", err) - } - return &ctypes.ResultBroadcastTx{}, nil -} +// // NOTE: tx must be signed +// func BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { +// err := mempoolReactor.BroadcastTx(tx, nil) +// if err != nil { +// return nil, fmt.Errorf("Error broadcasting transaction: %v", err) +// } +// return &ctypes.ResultBroadcastTx{}, nil +// } // Note: tx must be signed func BroadcastTxSync(tx txs.Tx) (*ctypes.ResultBroadcastTx, error) {