Skip to content

Commit

Permalink
pop
Browse files Browse the repository at this point in the history
  • Loading branch information
chadlagore committed Jun 17, 2017
1 parent 56dfcde commit 762b1a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ func (p *Pool) Update(b *blockchain.Block, bc *blockchain.BlockChain) bool {
return true
}

// GetTxns returns the the largest of l or size of pool transactions.
// It selects the highest priority transactions.
func (p *Pool) GetTxns(l int) []*blockchain.Transaction {
// PopTxns returns the the largest of l or size of pool transactions.
// It selects the highest priority transactions, and removes them from the pool.
func (p *Pool) PopTxns(l int) []*blockchain.Transaction {
if p.Len() == 0 {
return make([]*blockchain.Transaction, 0)
}
Expand All @@ -117,7 +117,9 @@ func (p *Pool) GetTxns(l int) []*blockchain.Transaction {
}
txns := make([]*blockchain.Transaction, l)
for i := 0; i < l; i++ {
txns[i] = p.GetN(i)
t := p.GetN(i)
txns[i] = t
p.Delete(t)
}
return txns
}
7 changes: 5 additions & 2 deletions pool/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,20 @@ func TestGetTxns(t *testing.T) {
}
}
nTxns := len(b.Transactions) + 12 // arbitrary.
txns := p.GetTxns(nTxns)
txns := p.PopTxns(nTxns)
for _, tr := range txns {
if ok, _ := b.ContainsTransaction(tr); !ok {
t.FailNow()
}
}
if p.Len() != 0 {
t.FailNow()
}
}

func TestGetNewBlockEmpty(t *testing.T) {
p := New()
txns := p.GetTxns(305)
txns := p.PopTxns(305)
if len(txns) != 0 {
t.FailNow()
}
Expand Down

0 comments on commit 762b1a1

Please sign in to comment.