Skip to content

Commit

Permalink
rename Set to Push
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlagore committed Jul 26, 2017
1 parent 16dde33 commit eefcbc3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func (a *App) HandleWork() {

// HandleTransaction handles new instance of TransactionWork.
func (a *App) HandleTransaction(txn *blockchain.Transaction) {
validTransaction := a.Pool.Set(txn, a.Chain)
validTransaction := a.Pool.Push(txn, a.Chain)
if validTransaction {
log.Debug("added transaction to pool from address: " + txn.Sender.Repr())
} else {
Expand Down
4 changes: 2 additions & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestHandleBlockOK(t *testing.T) {
// TODO: Start miner.

for i < 1000 {
a.Pool.SetUnsafe(blockchain.NewTestTransaction())
a.Pool.PushUnsafe(blockchain.NewTestTransaction())
i++
}

Expand All @@ -145,7 +145,7 @@ func TestHandleBlockNotOK(t *testing.T) {

// TODO: Start miner.
for i < 1000 {
a.Pool.SetUnsafe(blockchain.NewTestTransaction())
a.Pool.PushUnsafe(blockchain.NewTestTransaction())
i++
}

Expand Down
6 changes: 3 additions & 3 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func getIndex(a []*PooledTransaction, target time.Time, low, high int) int {

// Set inserts a transaction into the pool, returning
// true if the Transaction was inserted (was valid).
func (p *Pool) Set(t *blockchain.Transaction, bc *blockchain.BlockChain) bool {
func (p *Pool) Push(t *blockchain.Transaction, bc *blockchain.BlockChain) bool {
if ok, err := bc.ValidTransaction(t); ok {
p.set(t)
return true
Expand All @@ -80,8 +80,8 @@ func (p *Pool) Set(t *blockchain.Transaction, bc *blockchain.BlockChain) bool {
}
}

// SetUnsafe adds a transaction to the pool without validation.
func (p *Pool) SetUnsafe(t *blockchain.Transaction) {
// PushUnsafe adds a transaction to the pool without validation.
func (p *Pool) PushUnsafe(t *blockchain.Transaction) {
p.set(t)
}

Expand Down
16 changes: 8 additions & 8 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestGetAndSetTransaction(t *testing.T) {
t.FailNow()
}
tr := b.Transactions[1]
if !p.Set(tr, bc) {
if !p.Push(tr, bc) {
t.FailNow()
}

Expand All @@ -36,7 +36,7 @@ func TestGetAndSetTransaction(t *testing.T) {
func TestSetBadTransaction(t *testing.T) {
p := New()
bc := blockchain.NewTestBlockChain()
if p.Set(blockchain.NewTestTransaction(), bc) {
if p.Push(blockchain.NewTestTransaction(), bc) {
t.FailNow()
}
}
Expand All @@ -50,7 +50,7 @@ func TestUpdatePool(t *testing.T) {
}

for _, tr := range legitBlk.Transactions[1:] {
p.Set(tr, bc)
p.Push(tr, bc)
}
if p.Len() == 0 {
t.FailNow()
Expand All @@ -77,9 +77,9 @@ func TestGetIndex(t *testing.T) {
p := New()
numTxns := 1000
tr := blockchain.NewTestTransaction()
p.SetUnsafe(tr)
p.PushUnsafe(tr)
for i := 0; i < numTxns; i++ {
p.SetUnsafe(blockchain.NewTestTransaction())
p.PushUnsafe(blockchain.NewTestTransaction())
}
if p.GetIndex(tr) != 0 {
t.FailNow()
Expand All @@ -98,7 +98,7 @@ func TestNextBlock(t *testing.T) {
lastBlk := chain.Blocks[nBlks-1]
numTxns := 1000
for i := 0; i < numTxns; i++ {
p.SetUnsafe(blockchain.NewTestTransaction())
p.PushUnsafe(blockchain.NewTestTransaction())
}
b := p.NextBlock(chain, blockchain.NewWallet().Public(), 1<<18)
assert.NotNil(t, b)
Expand Down Expand Up @@ -127,8 +127,8 @@ func TestSetDedupes(t *testing.T) {
t1 := blockchain.NewTestTransaction()
t2 := blockchain.NewTestTransaction()
t1.Input.Hash = t2.Input.Hash
p.SetUnsafe(t1)
p.SetUnsafe(t2)
p.PushUnsafe(t1)
p.PushUnsafe(t2)
assert.Equal(t, p.Peek(), t2)
assert.Equal(t, p.Len(), 1)
}

0 comments on commit eefcbc3

Please sign in to comment.