@ -29,8 +29,6 @@ import (
"sync"
"sync"
"time"
"time"
"golang.org/x/net/context"
"github.com/ethereum/ethash"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
@ -48,7 +46,7 @@ import (
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"
"gopkg.in/fatih/set.v0 "
"golang.org/x/net/context "
)
)
const defaultGas = uint64 ( 90000 )
const defaultGas = uint64 ( 90000 )
@ -405,7 +403,7 @@ func NewPublicAccountAPI(am *accounts.Manager) *PublicAccountAPI {
}
}
// Accounts returns the collection of accounts this node manages
// Accounts returns the collection of accounts this node manages
func ( s * PublicAccountAPI ) Accounts ( ) ( [ ] accounts . Account , error ) {
func ( s * PublicAccountAPI ) Accounts ( ) [ ] accounts . Account {
return s . am . Accounts ( )
return s . am . Accounts ( )
}
}
@ -421,17 +419,13 @@ func NewPrivateAccountAPI(am *accounts.Manager) *PrivateAccountAPI {
}
}
// ListAccounts will return a list of addresses for accounts this node manages.
// ListAccounts will return a list of addresses for accounts this node manages.
func ( s * PrivateAccountAPI ) ListAccounts ( ) ( [ ] common . Address , error ) {
func ( s * PrivateAccountAPI ) ListAccounts ( ) [ ] common . Address {
accounts , err := s . am . Accounts ( )
accounts := s . am . Accounts ( )
if err != nil {
return nil , err
}
addresses := make ( [ ] common . Address , len ( accounts ) )
addresses := make ( [ ] common . Address , len ( accounts ) )
for i , acc := range accounts {
for i , acc := range accounts {
addresses [ i ] = acc . Address
addresses [ i ] = acc . Address
}
}
return addresses , nil
return addresses
}
}
// NewAccount will create a new account and returns the address for the new account.
// NewAccount will create a new account and returns the address for the new account.
@ -450,8 +444,9 @@ func (s *PrivateAccountAPI) UnlockAccount(addr common.Address, password string,
if duration == nil {
if duration == nil {
duration = rpc . NewHexNumber ( 300 )
duration = rpc . NewHexNumber ( 300 )
}
}
a := accounts . Account { Address : addr }
if err := s . am . TimedUnlock ( addr , password , time . Duration ( duration . Int ( ) ) * time . Second ) ; err != nil {
d := time . Duration ( duration . Int64 ( ) ) * time . Second
if err := s . am . TimedUnlock ( a , password , d ) ; err != nil {
glog . V ( logger . Info ) . Infof ( "%v\n" , err )
glog . V ( logger . Info ) . Infof ( "%v\n" , err )
return false
return false
}
}
@ -701,8 +696,8 @@ func (s *PublicBlockChainAPI) doCall(args CallArgs, blockNr rpc.BlockNumber) (st
// Retrieve the account state object to interact with
// Retrieve the account state object to interact with
var from * state . StateObject
var from * state . StateObject
if args . From == ( common . Address { } ) {
if args . From == ( common . Address { } ) {
accounts , err := s . am . Accounts ( )
accounts := s . am . Accounts ( )
if err != nil || len ( accounts ) == 0 {
if len ( accounts ) == 0 {
from = stateDb . GetOrNewStateObject ( common . Address { } )
from = stateDb . GetOrNewStateObject ( common . Address { } )
} else {
} else {
from = stateDb . GetOrNewStateObject ( accounts [ 0 ] . Address )
from = stateDb . GetOrNewStateObject ( accounts [ 0 ] . Address )
@ -912,40 +907,17 @@ func NewPublicTransactionPoolAPI(e *Ethereum, gpo *GasPriceOracle) *PublicTransa
// subscriptionLoop listens for events on the global event mux and creates notifications for subscriptions.
// subscriptionLoop listens for events on the global event mux and creates notifications for subscriptions.
func ( s * PublicTransactionPoolAPI ) subscriptionLoop ( ) {
func ( s * PublicTransactionPoolAPI ) subscriptionLoop ( ) {
sub := s . eventMux . Subscribe ( core . TxPreEvent { } )
sub := s . eventMux . Subscribe ( core . TxPreEvent { } )
accountTimeout := time . NewTicker ( 10 * time . Second )
for event := range sub . Chan ( ) {
tx := event . Data . ( core . TxPreEvent )
// only publish pending tx signed by one of the accounts in the node
if from , err := tx . Tx . FromFrontier ( ) ; err == nil {
accountSet := set . New ( )
if s . am . HasAddress ( from ) {
accounts , _ := s . am . Accounts ( )
s . muPendingTxSubs . Lock ( )
for _ , acc := range accounts {
for id , sub := range s . pendingTxSubs {
accountSet . Add ( acc . Address )
if sub . Notify ( tx . Tx . Hash ( ) ) == rpc . ErrNotificationNotFound {
}
delete ( s . pendingTxSubs , id )
for {
select {
case event := <- sub . Chan ( ) :
if event == nil {
continue
}
tx := event . Data . ( core . TxPreEvent )
if from , err := tx . Tx . FromFrontier ( ) ; err == nil {
if accountSet . Has ( from ) {
s . muPendingTxSubs . Lock ( )
for id , sub := range s . pendingTxSubs {
if sub . Notify ( tx . Tx . Hash ( ) ) == rpc . ErrNotificationNotFound {
delete ( s . pendingTxSubs , id )
}
}
}
s . muPendingTxSubs . Unlock ( )
}
}
case <- accountTimeout . C :
// refresh account list when accounts are added/removed from the node.
if accounts , err := s . am . Accounts ( ) ; err == nil {
accountSet . Clear ( )
for _ , acc := range accounts {
accountSet . Add ( acc . Address )
}
}
s . muPendingTxSubs . Unlock ( )
}
}
}
}
}
}
@ -1116,7 +1088,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (ma
// sign is a helper function that signs a transaction with the private key of the given address.
// sign is a helper function that signs a transaction with the private key of the given address.
func ( s * PublicTransactionPoolAPI ) sign ( address common . Address , tx * types . Transaction ) ( * types . Transaction , error ) {
func ( s * PublicTransactionPoolAPI ) sign ( address common . Address , tx * types . Transaction ) ( * types . Transaction , error ) {
acc := accounts . Account { address }
acc := accounts . Account { Address : address }
signature , err := s . am . Sign ( acc , tx . SigHash ( ) . Bytes ( ) )
signature , err := s . am . Sign ( acc , tx . SigHash ( ) . Bytes ( ) )
if err != nil {
if err != nil {
return nil , err
return nil , err
@ -1358,26 +1330,16 @@ func (s *PublicTransactionPoolAPI) SignTransaction(args SignTransactionArgs) (*S
// PendingTransactions returns the transactions that are in the transaction pool and have a from address that is one of
// PendingTransactions returns the transactions that are in the transaction pool and have a from address that is one of
// the accounts this node manages.
// the accounts this node manages.
func ( s * PublicTransactionPoolAPI ) PendingTransactions ( ) ( [ ] * RPCTransaction , error ) {
func ( s * PublicTransactionPoolAPI ) PendingTransactions ( ) [ ] * RPCTransaction {
accounts , err := s . am . Accounts ( )
if err != nil {
return nil , err
}
accountSet := set . New ( )
for _ , account := range accounts {
accountSet . Add ( account . Address )
}
pending := s . txPool . GetTransactions ( )
pending := s . txPool . GetTransactions ( )
transactions := make ( [ ] * RPCTransaction , 0 )
transactions := make ( [ ] * RPCTransaction , 0 )
for _ , tx := range pending {
for _ , tx := range pending {
if from , _ := tx . FromFrontier ( ) ; accountSet . Has ( from ) {
from , _ := tx . FromFrontier ( )
if s . am . HasAddress ( from ) {
transactions = append ( transactions , newRPCPendingTransaction ( tx ) )
transactions = append ( transactions , newRPCPendingTransaction ( tx ) )
}
}
}
}
return transactions
return transactions , nil
}
}
// NewPendingTransaction creates a subscription that is triggered each time a transaction enters the transaction pool
// NewPendingTransaction creates a subscription that is triggered each time a transaction enters the transaction pool
@ -1856,8 +1818,8 @@ func (s *PublicBlockChainAPI) TraceCall(args CallArgs, blockNr rpc.BlockNumber)
// Retrieve the account state object to interact with
// Retrieve the account state object to interact with
var from * state . StateObject
var from * state . StateObject
if args . From == ( common . Address { } ) {
if args . From == ( common . Address { } ) {
accounts , err := s . am . Accounts ( )
accounts := s . am . Accounts ( )
if err != nil || len ( accounts ) == 0 {
if len ( accounts ) == 0 {
from = stateDb . GetOrNewStateObject ( common . Address { } )
from = stateDb . GetOrNewStateObject ( common . Address { } )
} else {
} else {
from = stateDb . GetOrNewStateObject ( accounts [ 0 ] . Address )
from = stateDb . GetOrNewStateObject ( accounts [ 0 ] . Address )