Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #142 - Transform value receivers into pointer receivers #144

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/coin/skycoin/models/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/fibercrypto/FiberCryptoWallet/src/util"
)

func (addr SkycoinAddress) GetBalance(ticker string) (uint64, error) {
func (addr *SkycoinAddress) GetBalance(ticker string) (uint64, error) {

c, err := NewSkycoinApiClient(PoolSection)
if err != nil {
Expand All @@ -34,10 +34,10 @@ func (addr SkycoinAddress) GetBalance(ticker string) (uint64, error) {
return 0, errorTickerInvalid{ticker}
}
}
func (addr SkycoinAddress) ListAssets() []string {
func (addr *SkycoinAddress) ListAssets() []string {
return []string{Sky, CoinHour}
}
func (addr SkycoinAddress) ScanUnspentOutputs() core.TransactionOutputIterator {
func (addr *SkycoinAddress) ScanUnspentOutputs() core.TransactionOutputIterator {
c, err := NewSkycoinApiClient(PoolSection)
if err != nil {
println(err.Error())
Expand Down Expand Up @@ -68,7 +68,7 @@ func (addr SkycoinAddress) ScanUnspentOutputs() core.TransactionOutputIterator {

return NewSkycoinTransactionOutputIterator(skyOutputs)
}
func (addr SkycoinAddress) ListTransactions() core.TransactionIterator {
func (addr *SkycoinAddress) ListTransactions() core.TransactionIterator {

c, err := NewSkycoinApiClient(PoolSection)
if err != nil {
Expand All @@ -94,11 +94,11 @@ func (addr SkycoinAddress) ListTransactions() core.TransactionIterator {
return NewSkycoinTransactionIterator(transactions)

}
func (addr SkycoinAddress) ListPendingTransactions() (core.TransactionIterator, error) { //------TODO
func (addr *SkycoinAddress) ListPendingTransactions() (core.TransactionIterator, error) { //------TODO
return nil,nil
}

func (wlt RemoteWallet) GetBalance(ticker string) (uint64, error) {
func (wlt *RemoteWallet) GetBalance(ticker string) (uint64, error) {
c, err := NewSkycoinApiClient(wlt.poolSection)
if err != nil {
return 0, err
Expand All @@ -120,11 +120,11 @@ func (wlt RemoteWallet) GetBalance(ticker string) (uint64, error) {

}

func (wlt RemoteWallet) ListAssets() []string {
func (wlt *RemoteWallet) ListAssets() []string {
return []string{Sky, CoinHour}
}

func (wlt RemoteWallet) ScanUnspentOutputs() core.TransactionOutputIterator {
func (wlt *RemoteWallet) ScanUnspentOutputs() core.TransactionOutputIterator {
addressesIter, err := wlt.GetLoadedAddresses()
if err != nil {
return nil
Expand All @@ -139,7 +139,7 @@ func (wlt RemoteWallet) ScanUnspentOutputs() core.TransactionOutputIterator {
return NewSkycoinTransactionOutputIterator(unOuts)
}

func (wlt RemoteWallet) ListTransactions() core.TransactionIterator {
func (wlt *RemoteWallet) ListTransactions() core.TransactionIterator {
addressesIter, err := wlt.GetLoadedAddresses()
if err != nil {
return nil
Expand All @@ -155,7 +155,7 @@ func (wlt RemoteWallet) ListTransactions() core.TransactionIterator {
return NewSkycoinTransactionIterator(txns)
}

func (wlt RemoteWallet) ListPendingTransactions() (core.TransactionIterator, error) {
func (wlt *RemoteWallet) ListPendingTransactions() (core.TransactionIterator, error) {
c, err := NewSkycoinApiClient(PoolSection)
if err != nil {
return nil, err
Expand All @@ -172,7 +172,7 @@ func (wlt RemoteWallet) ListPendingTransactions() (core.TransactionIterator, err
return NewSkycoinTransactionIterator(txns), nil
}

func (wlt LocalWallet) GetBalance(ticker string) (uint64, error) {
func (wlt *LocalWallet) GetBalance(ticker string) (uint64, error) {
walletName := filepath.Join(wlt.WalletDir, wlt.Id)
walletLoaded, err := wallet.Load(walletName)
if err != nil {
Expand Down Expand Up @@ -223,11 +223,11 @@ func (wlt LocalWallet) GetBalance(ticker string) (uint64, error) {

}

func (wlt LocalWallet) ListAssets() []string {
func (wlt *LocalWallet) ListAssets() []string {
return []string{Sky, CoinHour}
}

func (wlt LocalWallet) ScanUnspentOutputs() core.TransactionOutputIterator {
func (wlt *LocalWallet) ScanUnspentOutputs() core.TransactionOutputIterator {
addressesIter, err := wlt.GetLoadedAddresses()
if err != nil {
return nil
Expand All @@ -242,7 +242,7 @@ func (wlt LocalWallet) ScanUnspentOutputs() core.TransactionOutputIterator {
return NewSkycoinTransactionOutputIterator(unOuts)
}

func (wlt LocalWallet) ListTransactions() core.TransactionIterator {
func (wlt *LocalWallet) ListTransactions() core.TransactionIterator {
addressesIter, err := wlt.GetLoadedAddresses()
if err != nil {
return nil
Expand All @@ -258,7 +258,7 @@ func (wlt LocalWallet) ListTransactions() core.TransactionIterator {
return NewSkycoinTransactionIterator(txns)
}

func (wlt LocalWallet) ListPendingTransactions() (core.TransactionIterator, error) { //------TODO
func (wlt *LocalWallet) ListPendingTransactions() (core.TransactionIterator, error) { //------TODO
c, err := NewSkycoinApiClient(PoolSection)
if err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions src/coin/skycoin/models/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ type SkycoinBlockchainStatus struct { //Implements BlockchainStatus interface
func NewSkycoinBlockchainStatus(invalidCacheTime uint64) *SkycoinBlockchainStatus {
return &SkycoinBlockchainStatus{CacheTime: invalidCacheTime}
}
func (ss SkycoinBlockchainStatus) GetCoinValue(coinvalue core.CoinValueKey, ticker string) (uint64, error) {
func (ss *SkycoinBlockchainStatus) GetCoinValue(coinvalue core.CoinValueKey, ticker string) (uint64, error) {
elapsed := uint64(time.Now().UTC().UnixNano()) - ss.lastTimeSupplyRequested
if elapsed > ss.CacheTime || ss.cachedStatus == nil {
if ss.cachedStatus == nil {
Expand All @@ -111,7 +111,7 @@ func (ss SkycoinBlockchainStatus) GetCoinValue(coinvalue core.CoinValueKey, tick
}
}

func (ss SkycoinBlockchainStatus) GetLastBlock() (core.Block, error) {
func (ss *SkycoinBlockchainStatus) GetLastBlock() (core.Block, error) {
elapsed := uint64(time.Now().UTC().UnixNano()) - ss.lastTimeSupplyRequested
if elapsed > ss.CacheTime || ss.cachedStatus == nil {
if ss.cachedStatus == nil {
Expand All @@ -124,7 +124,7 @@ func (ss SkycoinBlockchainStatus) GetLastBlock() (core.Block, error) {
return ss.cachedStatus.LastBlockInfo, nil
}

func (ss SkycoinBlockchainStatus) GetNumberOfBlocks() (uint64, error) {
func (ss *SkycoinBlockchainStatus) GetNumberOfBlocks() (uint64, error) {
if ss.cachedStatus == nil {
if ss.cachedStatus == nil {
ss.cachedStatus = new(SkycoinBlockchainInfo)
Expand All @@ -137,11 +137,11 @@ func (ss SkycoinBlockchainStatus) GetNumberOfBlocks() (uint64, error) {
return ss.cachedStatus.NumberOfBlocks.Current, nil
}

func (ss SkycoinBlockchainStatus) SetCacheTime(time uint64) {
func (ss *SkycoinBlockchainStatus) SetCacheTime(time uint64) {
ss.CacheTime = time
}

func (ss SkycoinBlockchainStatus) requestSupplyInfo() error {
func (ss *SkycoinBlockchainStatus) requestSupplyInfo() error {

c, err := NewSkycoinApiClient(PoolSection)
if err != nil {
Expand Down Expand Up @@ -181,7 +181,7 @@ func (ss SkycoinBlockchainStatus) requestSupplyInfo() error {
return nil
}

func (ss SkycoinBlockchainStatus) requestStatusInfo() error {
func (ss *SkycoinBlockchainStatus) requestStatusInfo() error {

c, err := NewSkycoinApiClient(PoolSection)
if err != nil {
Expand Down
15 changes: 6 additions & 9 deletions src/coin/skycoin/models/cipher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

type SkycoinAddressIterator struct { //Implements AddressIterator interfaces
current int
addresses []SkycoinAddress
addresses []core.Address
}

func (it *SkycoinAddressIterator) Value() core.Address {
Expand All @@ -22,13 +22,10 @@ func (it *SkycoinAddressIterator) Next() bool {
}

func (it *SkycoinAddressIterator) HasNext() bool {
if (it.current + 1) >= len(it.addresses) {
return false
}
return true
return (it.current + 1) < len(it.addresses)
}

func NewSkycoinAddressIterator(addresses []SkycoinAddress) *SkycoinAddressIterator {
func NewSkycoinAddressIterator(addresses []core.Address) *SkycoinAddressIterator {
return &SkycoinAddressIterator{addresses: addresses, current: -1}
}

Expand All @@ -37,14 +34,14 @@ type SkycoinAddress struct { //Implements Address and CryptoAccount interfaces
poolSection string
}

func (addr SkycoinAddress) IsBip32() bool {
func (addr *SkycoinAddress) IsBip32() bool {
return false
}

func (addr SkycoinAddress) String() string {
func (addr *SkycoinAddress) String() string {
return addr.address
}

func (addr SkycoinAddress) GetCryptoAccount() core.CryptoAccount {
func (addr *SkycoinAddress) GetCryptoAccount() core.CryptoAccount {
return addr
}
4 changes: 2 additions & 2 deletions src/coin/skycoin/models/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (sto *SkycoinPendingTransactionOutput) IsSpent() bool {
}

func (sto *SkycoinPendingTransactionOutput) GetAddress() core.Address {
return SkycoinAddress{address: sto.Output.Address}
return &SkycoinAddress{address: sto.Output.Address}
}

func (sto *SkycoinPendingTransactionOutput) GetCoins(ticker string) (uint64, error) {
Expand Down Expand Up @@ -357,7 +357,7 @@ func (out *SkycoinTransactionOutput) GetId() string {
}

func (out *SkycoinTransactionOutput) GetAddress() core.Address {
return SkycoinAddress{address:out.skyOut.Address}
return &SkycoinAddress{address:out.skyOut.Address}
}

func (out *SkycoinTransactionOutput) GetCoins(ticker string) (uint64, error) {
Expand Down
16 changes: 8 additions & 8 deletions src/coin/skycoin/models/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,32 @@ type SkycoinPexNode struct {
LastSeenOut int64
}

func (network SkycoinPexNode) GetIp() string {
func (network *SkycoinPexNode) GetIp() string {
return network.Ip
}

func (network SkycoinPexNode) GetPort() uint16 {
func (network *SkycoinPexNode) GetPort() uint16 {
return network.Port
}

func (network SkycoinPexNode) GetBlockHeight() uint64 {
func (network *SkycoinPexNode) GetBlockHeight() uint64 {
return network.Block
}

func (network SkycoinPexNode) IsTrusted() bool {
func (network *SkycoinPexNode) IsTrusted() bool {
return network.Source
}

func (network SkycoinPexNode) GetLastSeenIn() int64 {
func (network *SkycoinPexNode) GetLastSeenIn() int64 {
return network.LastSeenIn
}

func (network SkycoinPexNode) GetLastSeenOut() int64 {
func (network *SkycoinPexNode) GetLastSeenOut() int64 {
return network.LastSeenOut
}

func connectionsToNetwork(connection readable.Connection) SkycoinPexNode {
return SkycoinPexNode{
func connectionsToNetwork(connection readable.Connection) *SkycoinPexNode {
return &SkycoinPexNode{
Ip: strings.Split(connection.Addr, ":")[0],
Port: connection.ListenPort,
LastSeenIn: connection.LastSent,
Expand Down
Loading