Skip to content

Commit

Permalink
refs fibercrypto#142 Merge branch 'develop' of https://github.com/fib…
Browse files Browse the repository at this point in the history
…ercrypto/FiberCryptoWallet into stdevHan_t142_make_lint

 Conflicts:
	src/coin/skycoin/models/coin.go
	src/coin/skycoin/models/network.go
	src/coin/skycoin/models/wallet.go
	src/core/network.go
  • Loading branch information
Maykel Arias Torres committed Oct 15, 2019
2 parents 9f80473 + 484f179 commit c123e77
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 233 deletions.
14 changes: 7 additions & 7 deletions src/coin/skycoin/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (addr *SkycoinAddress) GetBalance(ticker string) (uint64, error) {
if err != nil {
return 0, err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
bl, err := c.Balance([]string{addr.address})

if err != nil {
Expand All @@ -43,7 +43,7 @@ func (addr *SkycoinAddress) ScanUnspentOutputs() core.TransactionOutputIterator
println(err.Error())
return nil
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
outputSummary, err := c.OutputsForAddresses([]string{addr.String()})
if err != nil {
println(err.Error())
Expand Down Expand Up @@ -74,7 +74,7 @@ func (addr *SkycoinAddress) ListTransactions() core.TransactionIterator {
if err != nil {
return nil
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
transactions := make([]core.Transaction, 0)
txn, _ := c.TransactionsVerbose([]string{addr.String()})

Expand Down Expand Up @@ -103,7 +103,7 @@ func (wlt *RemoteWallet) GetBalance(ticker string) (uint64, error) {
if err != nil {
return 0, err
}
defer core.GetMultiPool().Return(wlt.poolSection, c)
defer ReturnSkycoinClient(c)
bl, err := c.WalletBalance(wlt.Id)

if err != nil {
Expand Down Expand Up @@ -160,7 +160,7 @@ func (wlt *RemoteWallet) ListPendingTransactions() (core.TransactionIterator, er
if err != nil {
return nil, err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
response, err2 := c.WalletUnconfirmedTransactionsVerbose(wlt.GetId())
if err2 != nil {
return nil, err2
Expand Down Expand Up @@ -188,7 +188,7 @@ func (wlt *LocalWallet) GetBalance(ticker string) (uint64, error) {
if err != nil {
return 0, err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
outs, err := c.OutputsForAddresses(addrs)

if err != nil {
Expand Down Expand Up @@ -266,7 +266,7 @@ func (wlt *LocalWallet) ListPendingTransactions() (core.TransactionIterator, err
if err != nil {
return nil, err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
response, err2 := c.WalletUnconfirmedTransactionsVerbose(wlt.GetId())
if err2 != nil {
return nil, err2
Expand Down
4 changes: 2 additions & 2 deletions src/coin/skycoin/models/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (ss *SkycoinBlockchainStatus) requestSupplyInfo() error {
if err != nil {
return err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
coinSupply, err := c.CoinSupply()
if err != nil {
return err
Expand Down Expand Up @@ -187,7 +187,7 @@ func (ss *SkycoinBlockchainStatus) requestStatusInfo() error {
if err != nil {
return err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
blocks, err := c.LastBlocks(1)

if err != nil {
Expand Down
15 changes: 6 additions & 9 deletions src/coin/skycoin/models/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,8 @@ func (txn *SkycoinTransaction) GetStatus() core.TransactionStatus {
if err != nil {
return 0
}
defer core.GetMultiPool().Return(PoolSection, c)
txnU, err := c.Transaction(txn.skyTxn.Hash)
if err != nil {
return 0
}
defer ReturnSkycoinClient(c)
txnU, _ := c.Transaction(txn.skyTxn.Hash)
if txnU.Status.Confirmed {
txn.status = core.TXN_STATUS_CONFIRMED
return txn.status
Expand Down Expand Up @@ -332,7 +329,7 @@ func getSkycoinTransactionInputsFromTxnHash(hash string) ([]core.TransactionInpu
if err != nil {
return nil, err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
transaction, err := c.TransactionVerbose(hash)
if err != nil {
return nil, err
Expand All @@ -354,7 +351,7 @@ func getSkycoinTransactionInputsFromInputsHashes(inputsHashes []cipher.SHA256) (
if err != nil {
return nil, err
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)

for _, in := range inputsHashes {
ux, err := c.UxOut(in.String())
Expand Down Expand Up @@ -415,7 +412,7 @@ func (in *SkycoinTransactionInput) GetSpentOutput() core.TransactionOutput {
if err != nil {
return nil
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
out, err := c.UxOut(in.skyIn.Hash)
if err != nil {
return nil
Expand Down Expand Up @@ -533,7 +530,7 @@ func (out *SkycoinTransactionOutput) IsSpent() bool {
if err != nil {
return true
}
defer core.GetMultiPool().Return(PoolSection, c)
defer ReturnSkycoinClient(c)
ou, err := c.UxOut(out.skyOut.Hash)
if err != nil {
return false
Expand Down
71 changes: 63 additions & 8 deletions src/coin/skycoin/models/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,47 @@ import (

"github.com/fibercrypto/FiberCryptoWallet/src/core"
"github.com/skycoin/skycoin/src/api"
"github.com/skycoin/skycoin/src/coin"
"github.com/skycoin/skycoin/src/readable"
)

const (
PoolSection = "skycoin"
)

type SkycoinAPI interface {
Transaction(txid string) (*readable.TransactionWithStatus, error)
Transactions(addrs []string) ([]readable.TransactionWithStatus, error)
TransactionVerbose(txid string) (*readable.TransactionWithStatusVerbose, error)
TransactionsVerbose(addrs []string) ([]readable.TransactionWithStatusVerbose, error)
UxOut(uxID string) (*readable.SpentOutput, error)
PendingTransactionsVerbose() ([]readable.UnconfirmedTransactionVerbose, error)
CoinSupply() (*api.CoinSupply, error)
LastBlocks(n uint64) (*readable.Blocks, error)
BlockchainProgress() (*readable.BlockchainProgress, error)
Balance(addrs []string) (*api.BalanceResponse, error)
OutputsForAddresses(addrs []string) (*readable.UnspentOutputsSummary, error)
Wallet(id string) (*api.WalletResponse, error)
UpdateWallet(id, label string) error
NewWalletAddress(id string, n int, password string) ([]string, error)
Wallets() ([]api.WalletResponse, error)
CreateWallet(o api.CreateWalletOptions) (*api.WalletResponse, error)
EncryptWallet(id, password string) (*api.WalletResponse, error)
DecryptWallet(id, password string) (*api.WalletResponse, error)
WalletBalance(id string) (*api.BalanceResponse, error)
WalletUnconfirmedTransactionsVerbose(id string) (*api.UnconfirmedTxnsVerboseResponse, error)
NetworkConnections(filters *api.NetworkConnectionsFilter) (*api.Connections, error)
InjectTransaction(txn *coin.Transaction) (string, error)
WalletSignTransaction(req api.WalletSignTransactionRequest) (*api.CreateTransactionResponse, error)
WalletCreateTransaction(req api.WalletCreateTransactionRequest) (*api.CreateTransactionResponse, error)
CreateTransaction(req api.CreateTransactionRequest) (*api.CreateTransactionResponse, error)
}

type SkycoinConnectionFactory struct {
url string
}

func (cf *SkycoinConnectionFactory) Create() (core.PooledObject, error) {
func (cf *SkycoinConnectionFactory) Create() (interface{}, error) {

return api.NewClient(cf.url), nil
}
Expand All @@ -28,13 +58,27 @@ func NewSkycoinConnectionFactory(url string) *SkycoinConnectionFactory {
}
}

func NewSkycoinApiClient(section string) (*api.Client, error) {
pool := core.GetMultiPool()
obj, err := pool.Get(section)
type SkycoinApiClient struct {
*api.Client
pool core.MultiPoolSection
}

func (sc *SkycoinApiClient) returnToPool() {
sc.pool.Put(sc.Client)
}

func NewSkycoinApiClient(section string) (SkycoinAPI, error) {
mpool := core.GetMultiPool()
pool, err := mpool.GetSection(section)
if err != nil {
return nil, err
}

obj := pool.Get()

if err != nil {
for _, ok := err.(core.NotAvailableObjectsError); ok; _, ok = err.(core.NotAvailableObjectsError) {
_, err = pool.Get(section)
obj = pool.Get()
if err == nil {
break
}
Expand All @@ -46,7 +90,18 @@ func NewSkycoinApiClient(section string) (*api.Client, error) {
if !ok {
return nil, fmt.Errorf("There is not propers client in %s pool", section)
}
return skyApi, nil
return &SkycoinApiClient{
Client: skyApi,
pool: pool,
}, nil
}

func ReturnSkycoinClient(obj SkycoinAPI) {
poolObj, ok := obj.(*SkycoinApiClient)
if !ok {
return
}
poolObj.pool.Put(poolObj.Client)
}

func NewSkycoinPEX(poolSection string) *SkycoinPEX {
Expand All @@ -72,7 +127,7 @@ func (spex *SkycoinPEX) BroadcastTxn(txn core.Transaction) error {
if err != nil {
return err
}
defer core.GetMultiPool().Return(spex.poolSection, c)
defer ReturnSkycoinClient(c)
_, err = c.InjectTransaction(unTxn.txn)
if err != nil {
return err
Expand All @@ -86,7 +141,7 @@ func (spex *SkycoinPEX) GetTxnPool() (core.TransactionIterator, error) {
if err != nil {
return nil, err
}
defer core.GetMultiPool().Return(spex.poolSection, c)
defer ReturnSkycoinClient(c)
txns, err2 := c.PendingTransactionsVerbose()
if err2 != nil {
return nil, err2
Expand Down
Loading

0 comments on commit c123e77

Please sign in to comment.