From 3c7756fe379972d8f43a6910fe35af62efbcc5fd Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:24:15 -0500
Subject: [PATCH 1/9] Initial commit
---
LICENSE | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
README.md | 2 +
2 files changed, 123 insertions(+)
create mode 100644 LICENSE
create mode 100644 README.md
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0e259d4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,121 @@
+Creative Commons Legal Code
+
+CC0 1.0 Universal
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
+ HEREUNDER.
+
+Statement of Purpose
+
+The laws of most jurisdictions throughout the world automatically confer
+exclusive Copyright and Related Rights (defined below) upon the creator
+and subsequent owner(s) (each and all, an "owner") of an original work of
+authorship and/or a database (each, a "Work").
+
+Certain owners wish to permanently relinquish those rights to a Work for
+the purpose of contributing to a commons of creative, cultural and
+scientific works ("Commons") that the public can reliably and without fear
+of later claims of infringement build upon, modify, incorporate in other
+works, reuse and redistribute as freely as possible in any form whatsoever
+and for any purposes, including without limitation commercial purposes.
+These owners may contribute to the Commons to promote the ideal of a free
+culture and the further production of creative, cultural and scientific
+works, or to gain reputation or greater distribution for their Work in
+part through the use and efforts of others.
+
+For these and/or other purposes and motivations, and without any
+expectation of additional consideration or compensation, the person
+associating CC0 with a Work (the "Affirmer"), to the extent that he or she
+is an owner of Copyright and Related Rights in the Work, voluntarily
+elects to apply CC0 to the Work and publicly distribute the Work under its
+terms, with knowledge of his or her Copyright and Related Rights in the
+Work and the meaning and intended legal effect of CC0 on those rights.
+
+1. Copyright and Related Rights. A Work made available under CC0 may be
+protected by copyright and related or neighboring rights ("Copyright and
+Related Rights"). Copyright and Related Rights include, but are not
+limited to, the following:
+
+ i. the right to reproduce, adapt, distribute, perform, display,
+ communicate, and translate a Work;
+ ii. moral rights retained by the original author(s) and/or performer(s);
+iii. publicity and privacy rights pertaining to a person's image or
+ likeness depicted in a Work;
+ iv. rights protecting against unfair competition in regards to a Work,
+ subject to the limitations in paragraph 4(a), below;
+ v. rights protecting the extraction, dissemination, use and reuse of data
+ in a Work;
+ vi. database rights (such as those arising under Directive 96/9/EC of the
+ European Parliament and of the Council of 11 March 1996 on the legal
+ protection of databases, and under any national implementation
+ thereof, including any amended or successor version of such
+ directive); and
+vii. other similar, equivalent or corresponding rights throughout the
+ world based on applicable law or treaty, and any national
+ implementations thereof.
+
+2. Waiver. To the greatest extent permitted by, but not in contravention
+of, applicable law, Affirmer hereby overtly, fully, permanently,
+irrevocably and unconditionally waives, abandons, and surrenders all of
+Affirmer's Copyright and Related Rights and associated claims and causes
+of action, whether now known or unknown (including existing as well as
+future claims and causes of action), in the Work (i) in all territories
+worldwide, (ii) for the maximum duration provided by applicable law or
+treaty (including future time extensions), (iii) in any current or future
+medium and for any number of copies, and (iv) for any purpose whatsoever,
+including without limitation commercial, advertising or promotional
+purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
+member of the public at large and to the detriment of Affirmer's heirs and
+successors, fully intending that such Waiver shall not be subject to
+revocation, rescission, cancellation, termination, or any other legal or
+equitable action to disrupt the quiet enjoyment of the Work by the public
+as contemplated by Affirmer's express Statement of Purpose.
+
+3. Public License Fallback. Should any part of the Waiver for any reason
+be judged legally invalid or ineffective under applicable law, then the
+Waiver shall be preserved to the maximum extent permitted taking into
+account Affirmer's express Statement of Purpose. In addition, to the
+extent the Waiver is so judged Affirmer hereby grants to each affected
+person a royalty-free, non transferable, non sublicensable, non exclusive,
+irrevocable and unconditional license to exercise Affirmer's Copyright and
+Related Rights in the Work (i) in all territories worldwide, (ii) for the
+maximum duration provided by applicable law or treaty (including future
+time extensions), (iii) in any current or future medium and for any number
+of copies, and (iv) for any purpose whatsoever, including without
+limitation commercial, advertising or promotional purposes (the
+"License"). The License shall be deemed effective as of the date CC0 was
+applied by Affirmer to the Work. Should any part of the License for any
+reason be judged legally invalid or ineffective under applicable law, such
+partial invalidity or ineffectiveness shall not invalidate the remainder
+of the License, and in such case Affirmer hereby affirms that he or she
+will not (i) exercise any of his or her remaining Copyright and Related
+Rights in the Work or (ii) assert any associated claims and causes of
+action with respect to the Work, in either case contrary to Affirmer's
+express Statement of Purpose.
+
+4. Limitations and Disclaimers.
+
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
+ surrendered, licensed or otherwise affected by this document.
+ b. Affirmer offers the Work as-is and makes no representations or
+ warranties of any kind concerning the Work, express, implied,
+ statutory or otherwise, including without limitation warranties of
+ title, merchantability, fitness for a particular purpose, non
+ infringement, or the absence of latent or other defects, accuracy, or
+ the present or absence of errors, whether or not discoverable, all to
+ the greatest extent permissible under applicable law.
+ c. Affirmer disclaims responsibility for clearing rights of other persons
+ that may apply to the Work or any use thereof, including without
+ limitation any person's Copyright and Related Rights in the Work.
+ Further, Affirmer disclaims responsibility for obtaining any necessary
+ consents, permissions or other rights required for any use of the
+ Work.
+ d. Affirmer understands and acknowledges that Creative Commons is not a
+ party to this document and has no duty or obligation with respect to
+ this CC0 or use of the Work.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d287867
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
+# vanilla-js-browser-wallet
+A bare-bones bitcoin wallet for the base layer implemented in vanilla javascript
From e7f4fdaef4db8523ae37920b8c64527e27a041be Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:31:13 -0500
Subject: [PATCH 2/9] Update README.md
---
README.md | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index d287867..15ec3be 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,11 @@
-# vanilla-js-browser-wallet
+# Vanilla JS Browser Wallet
A bare-bones bitcoin wallet for the base layer implemented in vanilla javascript
+
+# Purpose
+This wallet is intended for use by JS hackers who want to add a basic bitcoin wallet to their website or chrome extension. You can copy the code from here and use it elsewhere.
+
+# Limitations
+
+The fee estimator needs some work. I wrote a spec sheet that has me create a variable that incorporates the dust limit plus some extra data depending on how many inputs a transaction has and at some point I got that variable mixed up with the dust limit itself. I need to fix that because right now this mistake causes the transaction builder to set the transaction fee higher than what you selected.
+
+When you start the wallet it is also kinda slow to display your balance and your first unused address. I use blockstream.info as a chain backend and it queries them every five seconds for a bunch of addresses -- at least 20 change addresses and 20 receive addresses (because I set a gap limit of 20) -- and when you start the wallet it won't show your balance until it's done with these queries. So be a little patient. Maybe I should add some sort of progress indicator.
From 057c65db85114b3e1f6c1e91adca98da76d9e2ca Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:31:38 -0500
Subject: [PATCH 3/9] Add files via upload
---
wallet.html | 642 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 642 insertions(+)
create mode 100644 wallet.html
diff --git a/wallet.html b/wallet.html
new file mode 100644
index 0000000..aef5ac1
--- /dev/null
+++ b/wallet.html
@@ -0,0 +1,642 @@
+
+
+
+
+ Bitcoin browser wallet
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Balance
+
+
+
+
+ sats
+
+
+
+
+
+
+
+ Write down your backup words or you may lose your money
+
+
×
+
+
+
+
+
+
+ Receive
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Send
+
+
+
+
+ Address
+
+
+
+
+
+ Amount
+
+
+
+
+
Sats per byte: 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
From e2bb5d0206d9dde95d17a96926e65b15b8156d45 Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:32:44 -0500
Subject: [PATCH 4/9] Update README.md
---
README.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/README.md b/README.md
index 15ec3be..3bd9095 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,11 @@
# Vanilla JS Browser Wallet
A bare-bones bitcoin wallet for the base layer implemented in vanilla javascript
+# How to use it
+Go here: [https://supertestnet.github.io/vanilla-js-browser-wallet/wallet.html](https://supertestnet.github.io/vanilla-js-browser-wallet/wallet.html)
+
+It should be pretty self explanatory, there's a send button, a receive button, and it displays your balance. That's all.
+
# Purpose
This wallet is intended for use by JS hackers who want to add a basic bitcoin wallet to their website or chrome extension. You can copy the code from here and use it elsewhere.
From 17d9ce55d4247ae13e4d38db9d55f5c6cc131b9c Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:34:34 -0500
Subject: [PATCH 5/9] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 3bd9095..5d7f05f 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ A bare-bones bitcoin wallet for the base layer implemented in vanilla javascript
# How to use it
Go here: [https://supertestnet.github.io/vanilla-js-browser-wallet/wallet.html](https://supertestnet.github.io/vanilla-js-browser-wallet/wallet.html)
-It should be pretty self explanatory, there's a send button, a receive button, and it displays your balance. That's all.
+It should be pretty self explanatory, there's a send button, a receive button, and the homepage displays your balance and backup words. That's all.
# Purpose
This wallet is intended for use by JS hackers who want to add a basic bitcoin wallet to their website or chrome extension. You can copy the code from here and use it elsewhere.
From 3b06601b67ba7c5c9d7b9c8bc70aad0d8050cc0e Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:34:54 -0500
Subject: [PATCH 6/9] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 5d7f05f..c5c5675 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@ A bare-bones bitcoin wallet for the base layer implemented in vanilla javascript
# How to use it
Go here: [https://supertestnet.github.io/vanilla-js-browser-wallet/wallet.html](https://supertestnet.github.io/vanilla-js-browser-wallet/wallet.html)
-It should be pretty self explanatory, there's a send button, a receive button, and the homepage displays your balance and backup words. That's all.
+It should be pretty self explanatory, there's a send button, a receive button, and the homepage displays your balance and backup words (which you can hide after you write them down). That's all.
# Purpose
This wallet is intended for use by JS hackers who want to add a basic bitcoin wallet to their website or chrome extension. You can copy the code from here and use it elsewhere.
From 14643a7f4d25ad37a31f2a031d598ee77957e879 Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:36:32 -0500
Subject: [PATCH 7/9] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index c5c5675..ad48546 100644
--- a/README.md
+++ b/README.md
@@ -13,4 +13,4 @@ This wallet is intended for use by JS hackers who want to add a basic bitcoin wa
The fee estimator needs some work. I wrote a spec sheet that has me create a variable that incorporates the dust limit plus some extra data depending on how many inputs a transaction has and at some point I got that variable mixed up with the dust limit itself. I need to fix that because right now this mistake causes the transaction builder to set the transaction fee higher than what you selected.
-When you start the wallet it is also kinda slow to display your balance and your first unused address. I use blockstream.info as a chain backend and it queries them every five seconds for a bunch of addresses -- at least 20 change addresses and 20 receive addresses (because I set a gap limit of 20) -- and when you start the wallet it won't show your balance until it's done with these queries. So be a little patient. Maybe I should add some sort of progress indicator.
+When you start the wallet it is also kinda slow to display your balance and your first unused address. I use blockstream.info as a chain backend and it queries them every five seconds for a bunch of addresses, namely, 20 or more change addresses plus 20 or more receive addresses (I set a gap limit of 20). When you start the wallet it won't show your balance until it's done with these queries. So be a little patient. Maybe I should add some sort of progress indicator.
From d3862b9cce5c570f91b44479756d7eeac248d091 Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Sat, 7 May 2022 02:36:54 -0500
Subject: [PATCH 8/9] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index ad48546..250e460 100644
--- a/README.md
+++ b/README.md
@@ -7,7 +7,7 @@ Go here: [https://supertestnet.github.io/vanilla-js-browser-wallet/wallet.html](
It should be pretty self explanatory, there's a send button, a receive button, and the homepage displays your balance and backup words (which you can hide after you write them down). That's all.
# Purpose
-This wallet is intended for use by JS hackers who want to add a basic bitcoin wallet to their website or chrome extension. You can copy the code from here and use it elsewhere.
+This wallet is intended for use by JS hackers who want to add a basic non-custodial bitcoin wallet to their website or chrome extension. You can copy the code from here and use it elsewhere.
# Limitations
From 19ae5097f4645bf5b1103a39abc04155a8b072fc Mon Sep 17 00:00:00 2001
From: supertestnet <58400631+supertestnet@users.noreply.github.com>
Date: Tue, 8 Nov 2022 18:16:40 -0600
Subject: [PATCH 9/9] Update wallet.html
---
wallet.html | 117 ++++++++++++++++++++++++++++++++++++----------------
1 file changed, 81 insertions(+), 36 deletions(-)
diff --git a/wallet.html b/wallet.html
index aef5ac1..a02a4a4 100644
--- a/wallet.html
+++ b/wallet.html
@@ -45,7 +45,7 @@
resolve( fullincome - fulloutgo );
};
}
- xhttp.open( "GET", "https://blockstream.info/testnet/api/address/" + address, true );
+ xhttp.open( "GET", "https://mempool.space/testnet/api/address/" + address, true );
xhttp.send();
});
}
@@ -77,7 +77,7 @@
resolve( obj );
}
}
- xhttp.open( "GET", "https://blockstream.info/testnet/api/address/" + address + "/utxo", true );
+ xhttp.open( "GET", "https://mempool.space/testnet/api/address/" + address + "/utxo", true );
xhttp.send();
});
}
@@ -155,7 +155,7 @@
resolve( false );
}
};
- xhttp.open( "GET", "https://blockstream.info/testnet/api/address/" + address, true );
+ xhttp.open( "GET", "https://mempool.space/testnet/api/address/" + address, true );
xhttp.send();
});
}
@@ -201,21 +201,22 @@
return Number( balance ).toString();
}
- function pushBTCpmt( rawtx ) {
- var xhttp = new XMLHttpRequest();
- xhttp.onreadystatechange = function() {
- if ( this.readyState == 4 && ( this.status == 200 || this.status == 201 ) ) {
- var json = JSON.parse( this.responseText );
- console.log( json );
- alert( "Your transaction has been broadcasted, your txid is: " + json[ "tx" ][ "hash" ] );
- }
- };
- xhttp.open( "POST", "https://api.blockcypher.com/v1/btc/test3/txs/push", true );
- xhttp.setRequestHeader( "Content-type", "text/plain" );
- xhttp.send( '{"tx":"' + rawtx + '"}' );
- }
+ function pushBTCpmt( rawtx ) {
+ var xhttp = new XMLHttpRequest();
+ xhttp.onreadystatechange = function() {
+ if ( this.readyState == 4 && ( this.status > 199 && this.status < 300 ) ) {
+ var response = this.responseText;
+ console.log( "Your transaction was broadcasted, your txid is: " + response );
+ }
+ };
+ xhttp.open( "POST", "https://mempool.space/testnet/api/tx", true );
+ xhttp.send( rawtx );
+ }
function craftTransaction( selected_utxos, to_amount, to_address, change_address, change_amount, sats_per_byte ) {
+ if ( !to_amount ) {
+ return;
+ }
if ( change_amount != 0 && change_address != "none" ) {
var psbt = new bitcoinjs.Psbt({ network: bitcoinjs.networks.testnet });
var i; for ( i=0; i 0 ) {
+ var change_amount = sum_of_the_values_of_each_input_to_this_transaction - ( to_amount + ( total_transaction_size * sats_per_byte ) );
+ } else {
+ var change_amount = sum_of_the_values_of_each_input_to_this_transaction - amount_plus_fee;
+ }
console.log( "the sum of the values of each input to this transaction is", sum_of_the_values_of_each_input_to_this_transaction );
console.log( "amount plus fee", amount_plus_fee );
- console.log( "the change amount should be the first number minus the second number, i.e.", change_amount );
- console.log( "there is change left over, namely", change_amount, "-- so we have to check if that is more than the dust limit" );
- if ( change_amount >= ( 250 + 50 * sats_per_byte ) ) {
- console.log( "the change amount --", change_amount, "-- is more than the dust limit, which is 250 + 50 * sats_per_byte i.e.", ( 250 + 50 * sats_per_byte ), "so we have to redo steps 4-9 with a new amount_plus_fee of the previous amount_plus_fee plus 50*sats_per_byte, i.e.", amount_plus_fee + 50*sats_per_byte, "but we have to keep the old values of utxos_available_for_this_transaction and utxos_in_this_transaction" );
+ console.log( "the change amount should be one of two values, either the first number minus the second number, i.e.", sum_of_the_values_of_each_input_to_this_transaction - amount_plus_fee, "or the first number minus the to_amount minus the total transaction size -- as long as I know it, currently it is thought to be", total_transaction_size, "and if that number is 0 it just means I do not know it -- multiplied by the sats_per_byte value, which is", sats_per_byte, "for a total of", sum_of_the_values_of_each_input_to_this_transaction - ( to_amount + ( total_transaction_size * sats_per_byte ) ) );
+ if ( change_amount > 0 ) {
+ console.log( "there is change left over, namely", change_amount, "-- so we have to check if that is more than the dust limit" );
+ } else {
+ console.log( "there is no change left over so I do not need a change output, yay!" );
+ }
+ if ( change_amount >= 250 ) {
+ console.log( "the change amount --", change_amount, "-- is equal to or more than the dust limit of this wallet, which is 250. (It used to be 250 + 50 * sats_per_byte i.e.", ( 250 + 50 * sats_per_byte ), "because I added some to the dust limit so that the change amount would not go lower than the dust limit once I add another output, but this caused problems and 250 is already a bit high anyway so I put it back to just 250.) So I have to redo steps 4-9. I used to use a new amount_plus_fee of the previous amount_plus_fee plus 50*sats_per_byte, i.e.", original_amount_plus_fee + 50*sats_per_byte, "because I figured the transaction size would have to rise by about 50 bytes, but it causes problems so now I am redoing it without changing anything. Also I have to remember to use the old values of utxos_available_for_this_transaction and utxos_in_this_transaction" );
var we_need_a_change_address = true;
- new_amount_plus_fee = amount_plus_fee + ( 50*sats_per_byte );
+ // new_amount_plus_fee = original_amount_plus_fee + ( 50*sats_per_byte );
+ new_amount_plus_fee = original_amount_plus_fee;
console.log( "original utxos available:", JSON.parse( original_utxos_available_for_this_transaction ) );
console.log( "original utxos in this tx:", JSON.parse( original_utxos_in_this_transaction ) );
- return addUtxosToTx( new_amount_plus_fee, JSON.parse( original_utxos_available_for_this_transaction ), JSON.parse( original_utxos_in_this_transaction ), sats_per_byte, true );
+ return addUtxosToTx( new_amount_plus_fee, JSON.parse( original_utxos_available_for_this_transaction ), JSON.parse( original_utxos_in_this_transaction ), sats_per_byte, true, this_addition_is_being_done_after_the_total_transaction_size_is_known, total_transaction_size, to_amount );
} else {
+ console.log( "there is a small possibility that this was mentioned earlier (if he change output was exactly equal to 0), but in case it was not, be aware that there is no change output because the change amount was lower than my dust threshhold and will therefore be dropped. That is good because it means I am using my coins efficiently and saving on fees" );
var we_need_a_change_address = false;
}
console.log( "sum of the values of each input to this transaction", sum_of_the_values_of_each_input_to_this_transaction );
@@ -342,7 +359,12 @@
array[ 5 ] = this_addition_is_being_done_because_of_a_change_address;
return array;
} else {
- var change_amount = sum_of_the_values_of_each_input_to_this_transaction - amount_plus_fee;
+ if ( total_transaction_size > 0 ) {
+ var change_amount = sum_of_the_values_of_each_input_to_this_transaction - ( to_amount + ( total_transaction_size * sats_per_byte ) );
+ } else {
+ var change_amount = sum_of_the_values_of_each_input_to_this_transaction - amount_plus_fee;
+ }
+ console.log( "ok this is part of the change path, my change value is", change_amount );
var array = [];
array[ 0 ] = utxos_available_for_this_transaction;
array[ 1 ] = utxos_in_this_transaction;
@@ -350,7 +372,8 @@
array[ 3 ] = change_amount;
array[ 4 ] = "the next field is true if we need a change address";
array[ 5 ] = this_addition_is_being_done_because_of_a_change_address;
- return array;
+ console.log( "I need a change address, right?", array[ 5 ] );
+ return array;
}
}
}
@@ -369,8 +392,23 @@
}
var original_utxos_available_for_this_transaction = JSON.stringify( utxos_available_for_this_transaction );
var original_utxos_in_this_transaction = JSON.stringify( utxos_in_this_transaction );
- var array = addUtxosToTx( amount_plus_fee, utxos_available_for_this_transaction, utxos_in_this_transaction, sats_per_byte, false );
- var adjusted_utxos_available_for_this_transaction = array[ 0 ];
+ var array = addUtxosToTx( amount_plus_fee, utxos_available_for_this_transaction, utxos_in_this_transaction, sats_per_byte, false, false, 0, toamount );
+ console.log( "here is array item 0:", array[ 0 ] );
+ console.log( "ok now I am checking if array item 0 satisfies an if condition:" );
+ if ( array[ 0 ].length > 0 ) {
+ console.log( "hmm, it did" );
+ } else {
+ console.log( "yay, it did not!" );
+ }
+ if ( array[ 0 ].length > 0 && array[ 1 ] && array[ 2 ] && array[ 3 ] && array[ 4 ] && array[ 5 ] ) {
+ var adjusted_utxos_available_for_this_transaction = array[ 0 ];
+ var adjusted_utxos_in_this_transaction = array[ 1 ];
+ amount_plus_fee = array[ 2 ];
+ } else {
+ var adjusted_utxos_available_for_this_transaction = [];
+ var adjusted_utxos_in_this_transaction = [];
+ amount_plus_fee = 0;
+ }
var adjusted_utxos_in_this_transaction = array[ 1 ];
amount_plus_fee = array[ 2 ];
if ( array[ 5 ] ) {
@@ -394,18 +432,23 @@
console.log( original_utxos_available_for_this_transaction );
console.log( JSON.parse( original_utxos_available_for_this_transaction ) );
console.log( "I will also check what the original utxos in the transaction are", JSON.parse( original_utxos_in_this_transaction ) );
- var new_array = addUtxosToTx( new_amount_plus_fee, JSON.parse( original_utxos_available_for_this_transaction ), JSON.parse( original_utxos_in_this_transaction ), sats_per_byte, false );
+ console.log( "Ok I am about to rerun addUtxosToTx with the new fee in mind. The most important variable for this is new_amount_plus_fee, which is the amount I am sending,", toamount, "plus a variable where the number of actual bytes in this transaction, i.e.", virtual_bytes, "is multiplied by the sats per byte value, i.e.", sats_per_byte, "to give a result of", real_fee, "which I add to my to_amount to get a total new_amount_plus_fee of", new_amount_plus_fee );
+ var new_array = addUtxosToTx( new_amount_plus_fee, JSON.parse( original_utxos_available_for_this_transaction ), JSON.parse( original_utxos_in_this_transaction ), sats_per_byte, false, true, virtual_bytes, toamount );
+ console.log( "I need a change address, right? (This should be at least the second time I am asking this)", new_array[ 5 ] );
var new_adjusted_utxos_available_for_this_transaction = new_array[ 0 ];
var new_adjusted_utxos_in_this_transaction = new_array[ 1 ];
new_amount_plus_fee = new_array[ 2 ];
var new_change_amount = new_array[ 3 ];
+ if( Number( new_array[ 3 ] ) >= 250 && ( !change_address || change_address == "none" ) && new_array[ 5 ] ) {
+ var change_address = await getFirstUnusedChangeAddress();
+ }
var new_txhex = craftTransaction( new_adjusted_utxos_in_this_transaction, toamount, toaddress, change_address, new_change_amount, sats_per_byte );
console.log( new_txhex );
var new_tx = bitcoinjs.Transaction.fromHex( new_txhex );
var new_virtual_bytes = tx.virtualSize();
if ( new_virtual_bytes == virtual_bytes ) {
console.log( "yay! The transaction is ready and here is its hex:", new_txhex );
- pushBTCpmt( new_txhex );
+ return new_txhex;
} else {
alert( "I tried to craft your transaction twice and I kept getting errors. Please contact the developer of this wallet for assistance." );
}
@@ -631,12 +674,14 @@
document.getElementById( "backup-line" ).style.display = "none";
});
//make the send money button send money
- document.getElementById( "send-money-button" ).addEventListener( "click", function() {
+ document.getElementById( "send-money-button" ).addEventListener( "click", async function() {
var to_address = document.getElementById( "send-address-input" ).value;
var amount_to_send = Number( document.getElementById( "send-amount-input" ).value );
var sats_per_byte = Number( document.getElementById( "sats_per_byte" ).innerText );
- sendFromUtxoSetToAddress( amount_to_send, to_address, sats_per_byte );
+ var txhex = await sendFromUtxoSetToAddress( amount_to_send, to_address, sats_per_byte );
+ console.log( "txhex:", txhex );
+ pushBTCpmt( txhex );
});