Skip to content

Commit

Permalink
refactor: remove unused WaitTransactionForXBlocks()
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Jan 21, 2020
1 parent 74f46d9 commit 035fcb5
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 73 deletions.
48 changes: 0 additions & 48 deletions aeternity/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,54 +83,6 @@ func (b ErrWaitTransaction) Error() string {
return fmt.Sprintf("%s: %s", errType, b.Err.Error())
}

// WaitForTransactionForXBlocks blocks until a transaction has been mined or X
// blocks have gone by, after which it returns an error. The node polling
// interval can be config.Configured with config.Tuning.ChainPollInterval.
func WaitForTransactionForXBlocks(c getTransactionByHashHeighter, txHash string, x uint64) (blockHeight uint64, blockHash string, wtError error) {
nodeHeight, err := c.GetHeight()
if err != nil {
wtError = ErrWaitTransaction{
NetworkErr: true,
TransactionErr: false,
Err: err,
}
return
}
endHeight := nodeHeight + x
for nodeHeight <= endHeight {
nodeHeight, err = c.GetHeight()
if err != nil {
wtError = ErrWaitTransaction{
NetworkErr: true,
TransactionErr: false,
Err: err,
}
return
}
tx, err := c.GetTransactionByHash(txHash)
if err != nil {
wtError = ErrWaitTransaction{
NetworkErr: false,
TransactionErr: true,
Err: err,
}
return
}

if tx.BlockHeight.LargerThanZero() {
bh := big.Int(tx.BlockHeight)
return bh.Uint64(), *tx.BlockHash, nil
}
time.Sleep(config.Tuning.ChainPollInterval)
}
wtError = ErrWaitTransaction{
NetworkErr: false,
TransactionErr: true,
Err: fmt.Errorf("%v blocks have gone by and %v still isn't in a block", x, txHash),
}
return
}

// SignBroadcast signs a transaction and broadcasts it to a node.
func SignBroadcast(tx transactions.Transaction, signingAccount *account.Account, n naet.PostTransactioner, networkID string) (txReceipt *TxReceipt, err error) {
signedTx, hash, signature, err := transactions.SignHashTx(signingAccount, tx, networkID)
Expand Down
15 changes: 0 additions & 15 deletions aeternity/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package aeternity
import (
"fmt"
"math/big"
"testing"
"time"

"github.com/aeternity/aepp-sdk-go/v7/account"
Expand Down Expand Up @@ -43,20 +42,6 @@ func (m *mockClient) GetTransactionByHash(hash string) (tx *models.GenericSigned
}
return tx, nil
}
func TestWaitForTransactionForXBlocks(t *testing.T) {
m := new(mockClient)
blockHeight, blockHash, err := WaitForTransactionForXBlocks(m, "th_transactionhash", 10)
if err != nil {
t.Fatal(err)
}
if blockHeight != 9 {
t.Fatalf("Expected mock blockHeight 9, got %v", blockHeight)
}
if blockHash != "bh_someblockhash" {
t.Fatalf("Expected mock blockHash bh_someblockhash, got %s", blockHash)
}
}

func Example() {
// Set the Network ID. For this example, setting the config.Node.NetworkID
// is actually not needed - but if you have other code that also needs to
Expand Down
10 changes: 0 additions & 10 deletions integration_test/testsetup.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ func getHeight(node *naet.Node) (h uint64) {
return
}

func waitForTransaction(node *naet.Node, hash string) (height uint64, microblockHash string, err error) {
height, microblockHash, err = aeternity.WaitForTransactionForXBlocks(node, hash, 10)
if err != nil {
// Sometimes, the tests want the tx to fail. Return the err to let them know.
return 0, "", err
}
fmt.Println("Transaction was found at", height, "microblockHash", microblockHash, "err", err)
return height, microblockHash, err
}

func fundAccount(t *testing.T, node *naet.Node, source, destination *account.Account, amount *big.Int) {
ttlnoncer := transactions.NewTTLNoncer(node)
fmt.Println("Funding account", destination.Address)
Expand Down

0 comments on commit 035fcb5

Please sign in to comment.