diff --git a/dispenser.html b/dispenser.html new file mode 100644 index 0000000..9b0c908 --- /dev/null +++ b/dispenser.html @@ -0,0 +1,269 @@ + + + + + Create a Counterparty Dispenser w/ Electrum + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Create Dispenser

+
UTXO (Input Coin)
+

+
Asset
+

+
Amount to EscrowMax
+

+
Amount to Give per Dispense
+

+
Divisible
+

+
BTC to Charge per Dispense
+

+
Optional Dispenser Address
+

+
Optional Tip to Developer (BTC)Suggested: 0.0001
+
+

+ This is an experimental script. Peer review pending. Your tokens may get lost. Use at own risk!
+   + +

+ +
+ + + + diff --git a/index.html b/index.html index 1dbb07c..ca98655 100644 --- a/index.html +++ b/index.html @@ -32,6 +32,7 @@ const TO_RECEIVER = 0.00005420; //BTC dust sent along asset const forms = [ ['Send', 'send.html'], + ['Sell (Dispenser)', 'dispenser.html'], ['Sweep', 'sweep.html'], ['Broadcast Text', 'broadcast_text.html'], ['Broadcast File (CIP33)', 'cip33_broadcast.html'], @@ -202,7 +203,7 @@ function displayBalances() { let html = ''; - let url_send = 'send.html?asset={asset}&longname={longname}&max={max}&div={div}&address={addr}&utxo={utxo}'; + let url_send = 'asset={asset}&longname={longname}&max={max}&div={div}&address={addr}&utxo={utxo}'; //UTXOs let utxo = ''; @@ -238,10 +239,10 @@ send_link = send_link.replace('{div}', balances[i].divisibility); send_link = send_link.replace('{addr}', address); send_link = send_link.replace('{utxo}', utxo); - send_links.push('Send'); + send_links.push('Send | Sell'); if (balances[i].asset == 'XCP') { xcp_balance = balances[i].quantity; - send_link_xcp = 'Send'; + send_link_xcp = 'Send | Sell'; } } } diff --git a/js/xcp/build_tx_msg.js b/js/xcp/build_tx_msg.js index a21c280..918ee58 100644 --- a/js/xcp/build_tx_msg.js +++ b/js/xcp/build_tx_msg.js @@ -62,4 +62,20 @@ function msg_broadcast(text, ts = '', value = 0, fee = 0) { let text_len_hex = text_len.toString(16).padStart(2, '0'); return prefix_hex + msg_id_hex + ts_hex + value_hex + fee_hex + text_len_hex + text_hex; //return prefix_hex + msg_id_hex + ts_hex + value_hex + fee_hex + text_len_hex + text_hex; +} + +function msg_create_dispenser(asset, amount_escrow, amount_give, amount_btc, dispenser_address = '') { + const msg_id = 12; + let status_hex = '00'; + let msg_id_hex = msg_id.toString(16).padStart(2, '0'); + let asset_hex = asset_id_hex(asset).padStart(16, '0'); + let amount_escrow_hex = BigInt(amount_escrow).toString(16).padStart(16, '0'); + let amount_give_hex = BigInt(amount_give).toString(16).padStart(16, '0'); + let amount_btc_hex = BigInt(amount_btc).toString(16).padStart(16, '0'); + let dispenser_address_hex = ''; + if (dispenser_address != '') { + status_hex = '01'; + dispenser_address_hex = address_to_hex(dispenser_address); + } + return prefix_hex + msg_id_hex + asset_hex + amount_give_hex + amount_escrow_hex + amount_btc_hex + status_hex + dispenser_address_hex; } \ No newline at end of file diff --git a/js/xcp/decode_tx_msg.js b/js/xcp/decode_tx_msg.js index 52e8ae4..504595c 100644 --- a/js/xcp/decode_tx_msg.js +++ b/js/xcp/decode_tx_msg.js @@ -59,6 +59,22 @@ function decode_tx(msg, utxo = '') { info['sweep_type'] = sweep_types[flag]; } + if (msg_id == 12) { //Dispenser + asset_id_hex = msg.slice(0,16); + msg = msg.slice(16); + give_hex = msg.slice(0,16); + msg = msg.slice(16); + escrow_hex = msg.slice(0,16); + msg = msg.slice(16); + btc_hex = msg.slice(0,16); + msg = msg.slice(16); + dispenser_status = msg.slice(0,2); + msg = msg.slice(2); + if (dispenser_status == '01') { + addr_hex = msg; + } + } + if (msg_id == 30) { //Broadcast let ts_hex = msg.slice(0,8); msg = msg.slice(8); @@ -89,6 +105,27 @@ function decode_tx(msg, utxo = '') { info['amount_display'] = sat_to_display(amount, div); } + //for dispensers there are three kinds of 'amount'; give, escrow, btc + if (msg_id == 12) { + if (give_hex != '') { + let amount = BigInt('0x'+give_hex).toString(10); + let div = get_divisibility(asset); + info['give_amount'] = amount; + info['give_amount_display'] = sat_to_display(amount, div); + } + if (escrow_hex != '') { + let amount = BigInt('0x'+escrow_hex).toString(10); + let div = get_divisibility(asset); + info['escrow_amount'] = amount; + info['escrow_amount_display'] = sat_to_display(amount, div); + } + if (btc_hex != '') { + let amount = BigInt('0x'+btc_hex).toString(10); + info['btc_amount'] = amount; + info['btc_amount_display'] = sat_to_display(amount, 'div'); + } + } + if (addr_hex != '') { info['address'] = hex_to_address(addr_hex); } @@ -103,6 +140,7 @@ function decode_tx(msg, utxo = '') { + //** ADDRESS FUNCTIONS **// function hex_to_address(hex) { //21 byte hex encoded in cntrprty message let version_byte = hex.substring(0,2); diff --git a/js/xcp/display.js b/js/xcp/display.js index cceee66..5361927 100644 --- a/js/xcp/display.js +++ b/js/xcp/display.js @@ -4,7 +4,7 @@ const tip_btc = '0'; const wallet_header = `XCP Opreturn Builder for Electrum
{address}
{utxo}
Alpha release. For testing only!
`; -const wallet_footer = `

Footer goes here

`; +const wallet_footer = `

 

`; function addr_short(address, start = 4, end = 2) { if (address == '') return '';