mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-01 07:42:17 +00:00
Fix a bug in Transaction.getValueSentFromMe() in which inputs connected to outputs that existed in the wallet but were not actually owned by us were counted. Resolves issue 36. Patch from Jan Møller.
This commit is contained in:
parent
bcff039a62
commit
2c74beb9f5
1
AUTHORS
1
AUTHORS
@ -6,3 +6,4 @@ Micheal Swiggs <bobby.simpson87@gmail.com>
|
|||||||
Gary Rowe <g.rowe@froot.co.uk>
|
Gary Rowe <g.rowe@froot.co.uk>
|
||||||
Noa Resare <noa@resare.com>
|
Noa Resare <noa@resare.com>
|
||||||
John Sample <jwsample@gmail.com>
|
John Sample <jwsample@gmail.com>
|
||||||
|
Jan Møller <jan.moller@gmail.com>
|
@ -170,6 +170,10 @@ public class Transaction extends Message implements Serializable {
|
|||||||
connected = input.getConnectedOutput(wallet.pending);
|
connected = input.getConnectedOutput(wallet.pending);
|
||||||
if (connected == null)
|
if (connected == null)
|
||||||
continue;
|
continue;
|
||||||
|
// The connected output may be the change to the sender of a previous input sent to this wallet. In this
|
||||||
|
// case we ignore it.
|
||||||
|
if (!connected.isMine(wallet))
|
||||||
|
continue;
|
||||||
v = v.add(connected.getValue());
|
v = v.add(connected.getValue());
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
@ -35,10 +35,11 @@ public class WalletTest {
|
|||||||
private Address myAddress;
|
private Address myAddress;
|
||||||
private Wallet wallet;
|
private Wallet wallet;
|
||||||
private BlockStore blockStore;
|
private BlockStore blockStore;
|
||||||
|
private ECKey myKey;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
ECKey myKey = new ECKey();
|
myKey = new ECKey();
|
||||||
myAddress = myKey.toAddress(params);
|
myAddress = myKey.toAddress(params);
|
||||||
wallet = new Wallet(params);
|
wallet = new Wallet(params);
|
||||||
wallet.addKey(myKey);
|
wallet.addKey(myKey);
|
||||||
@ -212,6 +213,23 @@ public class WalletTest {
|
|||||||
assertEquals(nanos, send2.getValueSentFromMe(wallet));
|
assertEquals(nanos, send2.getValueSentFromMe(wallet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void transactions() throws Exception {
|
||||||
|
// This test covers a bug in which Transaction.getValueSentFromMe was calculating incorrectly.
|
||||||
|
Transaction tx = createFakeTx(Utils.toNanoCoins(1, 0), myAddress);
|
||||||
|
// Now add another output (ie, change) that goes to some other address.
|
||||||
|
Address someOtherGuy = new ECKey().toAddress(params);
|
||||||
|
TransactionOutput output = new TransactionOutput(params, tx, Utils.toNanoCoins(0, 5), someOtherGuy);
|
||||||
|
tx.addOutput(output);
|
||||||
|
wallet.receive(tx, null, BlockChain.NewBlockType.BEST_CHAIN);
|
||||||
|
// Now the other guy creates a transaction which spends that change.
|
||||||
|
Transaction tx2 = new Transaction(params);
|
||||||
|
tx2.addInput(output);
|
||||||
|
tx2.addOutput(new TransactionOutput(params, tx2, Utils.toNanoCoins(0, 5), myAddress));
|
||||||
|
// tx2 doesn't send any coins from us, even though the output is in the wallet.
|
||||||
|
assertEquals(Utils.toNanoCoins(0, 0), tx2.getValueSentFromMe(wallet));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void finneyAttack() throws Exception {
|
public void finneyAttack() throws Exception {
|
||||||
// A Finney attack is where a miner includes a transaction spending coins to themselves but does not
|
// A Finney attack is where a miner includes a transaction spending coins to themselves but does not
|
||||||
|
Loading…
Reference in New Issue
Block a user