Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Litecoin: Fix fees
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlie Lee committed Sep 13, 2016
1 parent 015aad5 commit 759f37d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Transaction.DUST_AMOUNT = 546;
Transaction.FEE_SECURITY_MARGIN = 15;

// max amount of satoshis in circulation
Transaction.MAX_MONEY = 21000000 * 1e8;
Transaction.MAX_MONEY = 84000000 * 1e8; // Litecoin has 84M coins

// nlocktime limit to be considered block height rather than a timestamp
Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT = 5e8;
Expand All @@ -78,7 +78,7 @@ Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT = 5e8;
Transaction.NLOCKTIME_MAX_VALUE = 4294967295;

// Value used for fee estimation (satoshis per kilobyte)
Transaction.FEE_PER_KB = 10000;
Transaction.FEE_PER_KB = 100000; // Litecoin default fees is 0.001 LTC

// Safe upper bound for change address script size in bytes
Transaction.CHANGE_OUTPUT_MAX_SIZE = 20 + 4 + 34 + 4;
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions test/data/tx_creation.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"txId": "a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458",
"outputIndex": 0,
"script": "OP_DUP OP_HASH160 20 0x88d9931ea73d60eaf7e5671efc0552b912911f2a OP_EQUALVERIFY OP_CHECKSIG",
"satoshis": 1020000
"satoshis": 1110000
}],
"to", ["mrU9pEmAx26HcbKVrABvgL7AwA5fjNFoDc", 1010000],
"sign", ["cSBnVM4xvxarwGQuAfQFwqDg9k5tErHUHzgWsEfD4zdwUasvqRVY"],
Expand All @@ -17,7 +17,7 @@
"vout": 1,
"address": "mgBCJAsvzgT2qNNeXsoECg2uPKrUsZ76up",
"scriptPubKey": "76a914073b7eae2823efa349e3b9155b8a735526463a0f88ac",
"amount": 0.01080000
"amount": 0.01170000
}],
"to", ["mn9new5vPYWuVN5m3gUBujfKh1uPQvR9mf", 500000],
"to", ["mw5ctwgEaNRbxkM4JhXH3rp5AyGvTWDZCD", 570000],
Expand All @@ -40,7 +40,7 @@
"address": "mw5ctwgEaNRbxkM4JhXH3rp5AyGvTWDZCD",
"account": "",
"scriptPubKey": "76a914aab76ba4877d696590d94ea3e02948b55294815188ac",
"amount": 0.00570000,
"amount": 0.00660000,
"confirmations": 0
}]
],
Expand All @@ -56,22 +56,22 @@
"txid": "f50e13cecda9a438ebd7df213a2899e42b2461a18d4630ee773d26b4f2688bdc",
"vout": 1,
"scriptPubKey": "76a914089acaba6af8b2b4fb4bed3b747ab1e4e60b496588ac",
"amount": 0.01
"amount": 0.0109
}],
"to", ["n3riXZowrjGnY74rx7Hdi9wCyvgyJC28zZ", 990000],
"sign", ["cPwWtDztEgRCMCU8pMQp4HgphvyadrAsYBrCjXUZuDSmnZkyoyNF"],
"serialize", "0100000001dc8b68f2b4263d77ee30468da161242be499283a21dfd7eb38a4a9cdce130ef5010000006a473044022012610834051e6af8594dd5d9c47123d6ce03537d321f9fe3f6ff244b23f47dd5022034901bb0d83688758a9248fdef48bd2000b55cf70111cbef8f206e72a31aaf61012103e26b47e7c0d8946954bf9dd4bc7f9e415437eb98271d05f69e78cef8fc6c9a54ffffffff01301b0f00000000001976a914f50f9826ef186074c6fe206cca6b71472ff07ba888ac00000000"
],
[
"from", [{
"address":"38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z","txid":"073281b2cc94e879aaf30ea2e92947d9827b270015849d3a5b96a89ee15bfa66","vout":0,"ts":1418877950,"scriptPubKey":"a9144de752833233fe69a20064f29b2ca0f6399c8af387","amount":0.00318512,"confirmationsFromCache":false
"address":"38nw4sTs3fCH1YiBjYeQAX1t9eWMxpek8Z","txid":"073281b2cc94e879aaf30ea2e92947d9827b270015849d3a5b96a89ee15bfa66","vout":0,"ts":1418877950,"scriptPubKey":"a9144de752833233fe69a20064f29b2ca0f6399c8af387","amount":0.00408512,"confirmationsFromCache":false
}, ["03411e021210a933c247ea9c8dad4bbead281597d508ad84e899de13e4ce98b4ba", "03bda2c3cc11a391b36e3d695b03ab42b96fe04086b2349056108d858983e60dab", "03c16e6ecf4e02bf9db23d3247ab92db8881f0866133ffb530c3470f6d8dea7330"], 2],
"to", ["3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9", 300299],
"sign", [["T9oGpupr8xxEwtZxv24hsjVmYm38ULAzWpzwarp1tYD7xWtGUbGL", "T9QLZR1Z9DeCJ2GRUZDQbkYff5ANA8npyErW8GB3KVioKhBw2119"]],
"serialize", "010000000166fa5be19ea8965b3a9d841500277b82d94729e9a20ef3aa79e894ccb281320700000000fc0047304402202f66fcfc0d5bff109ec12327ca37e0bc7722d08da9538f12468994799534bed602203a0b374f3a6810b0ee26028c390e14f5b6bada8fa390f4364d70d04aee240d350147304402206757f710f25937cd846fd8c56687c463a4561e9e0421fc173c78eaf2de9b9a7d02204995db6b81513b67a42b09dabab6ed4cb90901c52f6f945b768827a9390bda60014c69522103411e021210a933c247ea9c8dad4bbead281597d508ad84e899de13e4ce98b4ba2103bda2c3cc11a391b36e3d695b03ab42b96fe04086b2349056108d858983e60dab2103c16e6ecf4e02bf9db23d3247ab92db8881f0866133ffb530c3470f6d8dea733053aeffffffff010b9504000000000017a9146c8d8b04c6a1e664b1ec20ec932760760c97688e8700000000"
],
[
"from", [{"address":"3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9","txid":"afbf98ca4a43db8915d75184b5204fbe71d916482adfe85cb0ed3635764fc220","vout":0,"ts":1418878108,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00318512,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2
"from", [{"address":"3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9","txid":"afbf98ca4a43db8915d75184b5204fbe71d916482adfe85cb0ed3635764fc220","vout":0,"ts":1418878108,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00408512,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2
],
"from", [
{"address":"3BazTqvkvEBcWk7J4sbgRnxUw6rjYrogf9","txid":"dc2e197ab72f71912c39bc23a42d823a3aa8d469fe65eb591c086e60d14c64a0","vout":0,"ts":1418878014,"scriptPubKey":"a9146c8d8b04c6a1e664b1ec20ec932760760c97688e87","amount":0.00300299,"confirmationsFromCache":false}, ["020483ebb834d91d494a3b649cf0e8f5c9c4fcec5f194ab94341cc99bb440007f2", "0271ebaeef1c2bf0c1a4772d1391eab03e4d96a6e9b48551ab4e4b0d2983eb452b", "03a659828aabe443e2dedabb1db5a22335c5ace5b5b7126998a288d63c99516dd8"], 2],
Expand Down
21 changes: 14 additions & 7 deletions test/transaction/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ describe('Transaction', function() {
script: Script.buildPublicKeyHashOut(fromAddress).toString(),
satoshis: 100000
};
var simpleUtxoWith1000000Satoshis = {
address: fromAddress,
txId: 'a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458',
outputIndex: 0,
script: Script.buildPublicKeyHashOut(fromAddress).toString(),
satoshis: 1000000
};
var anyoneCanSpendUTXO = JSON.parse(JSON.stringify(simpleUtxoWith100000Satoshis));
anyoneCanSpendUTXO.script = new Script().add('OP_TRUE');
var toAddress = 'mrU9pEmAx26HcbKVrABvgL7AwA5fjNFoDc';
Expand Down Expand Up @@ -289,12 +296,12 @@ describe('Transaction', function() {
describe('change address', function() {
it('can calculate simply the output amount', function() {
var transaction = new Transaction()
.from(simpleUtxoWith100000Satoshis)
.to(toAddress, 50000)
.from(simpleUtxoWith1000000Satoshis)
.to(toAddress, 500000)
.change(changeAddress)
.sign(privateKey);
transaction.outputs.length.should.equal(2);
transaction.outputs[1].satoshis.should.equal(40000);
transaction.outputs[1].satoshis.should.equal(400000);
transaction.outputs[1].script.toString()
.should.equal(Script.fromAddress(changeAddress).toString());
var actual = transaction.getChangeOutput().script.toString();
Expand All @@ -303,8 +310,8 @@ describe('Transaction', function() {
});
it('accepts a P2SH address for change', function() {
var transaction = new Transaction()
.from(simpleUtxoWith100000Satoshis)
.to(toAddress, 50000)
.from(simpleUtxoWith1000000Satoshis)
.to(toAddress, 500000)
.change(changeAddressP2SH)
.sign(privateKey);
transaction.outputs.length.should.equal(2);
Expand Down Expand Up @@ -919,7 +926,7 @@ describe('Transaction', function() {
.change(changeAddress)
.to(toAddress, 1000);
transaction.inputAmount.should.equal(100000000);
transaction.outputAmount.should.equal(99990000);
transaction.outputAmount.should.equal(99900000);
});
it('returns correct values for coinjoin transaction', function() {
// see livenet tx c16467eea05f1f30d50ed6dbc06a38539d9bb15110e4b7dc6653046a3678a718
Expand Down Expand Up @@ -1011,7 +1018,7 @@ describe('Transaction', function() {
tx.outputs.length.should.equal(2);
tx.outputs[0].satoshis.should.equal(10000000);
tx.outputs[0].script.toAddress().toString().should.equal(toAddress);
tx.outputs[1].satoshis.should.equal(89990000);
tx.outputs[1].satoshis.should.equal(89900000);
tx.outputs[1].script.toAddress().toString().should.equal(changeAddress);
});

Expand Down

0 comments on commit 759f37d

Please sign in to comment.