function crosschain_tab_builder2(div, selector){
var ZERO = btoa(array_to_string(integer_to_array(0, 32)));
var fee = 200000;
var display = document.createElement("div");
display.innerHTML = "ready.";
var title = document.createElement("h3");
title.innerHTML = "Crosschain Decentralized Exchange ";
div.appendChild(title);
var details = document.createElement("p");
details.innerHTML = "Sell a currency on another blockchain to buy VEO. Manage these kinds of trades.";
div.appendChild(details);
div.appendChild(display);
var IP = default_ip();
//Make trade offer interface
var trade_offer_title = document.createElement("h3");
trade_offer_title.innerHTML = "Make Trade Offer";
div.appendChild(trade_offer_title);
var other_blockchain_input = text_input("Name of the other blockchain where you want to sell value. (i.e. Ethereum)", div);
div.appendChild(br());
var ticker_input = text_input("Name of the currency that you want to sell. (i.e. Eth)", div);
div.appendChild(br());
var spend_amount_input = text_input("Amount of currency you want to send. (i.e. 0.15)", div);
div.appendChild(br());
var receive_amount_input = text_input("Amount of VEO you want to receive. (i.e. 1.205)", div);
div.appendChild(br());
var advanced_div = document.createElement("div");
advanced_div.appendChild(br());
var advanced_interface = document.createElement("div");
var more_button = button_maker2("more options", function(){
advanced_div.innerHTML = "";
advanced_div.appendChild(advanced_interface);
});
var less_button = button_maker2("less options", function(){
advanced_div.innerHTML = "
";
});
div.appendChild(more_button);
div.appendChild(less_button);
div.appendChild(br());
div.appendChild(advanced_div);
var security_amount_input = text_input("How much currency should you need to lock into the contract as a security deposit to enforce that you actually deliver. (default is 10% the amount you are selling) (i.e. 0.015)", advanced_interface);
advanced_interface.appendChild(br());
var hours_input = text_input("How many hours do you have until the money needs to arrive in their account on the other blockchain. Don't make it too big, we need to wait this long to run the oracle, but also don't make it too small, as if you fail to deliver the currency in time, then you lose your safety deposit. (i.e. 48)", advanced_interface);
hours_input.value = "48";
advanced_interface.appendChild(br());
//look at create_tab_builder to see about dates.
var blocks_till_expires_text = text_input("How many Amoveo blocks until your trade offer should expire as invalid. (Amoveo has about 130 blocks per day)(i.e. 130)", advanced_interface);
blocks_till_expires_text.value = "130";
advanced_interface.appendChild(br());
//test values
other_blockchain_input.value = "Bitcoin";
ticker_input.value = "BTC";
receive_amount_input.value = "0.1";
spend_amount_input.value = "0.000001";
/*
//security_amount_input.value = "0.3";
hours_input.value = "48";
blocks_till_expires_text.value = "30";
*/
var button = button_maker3("make crosschain trade offer", crosschain_offer);
div.appendChild(button);
div.appendChild(br());
async function crosschain_offer(button){
var amount1 = Math.round(parseFloat(receive_amount_input.value, 10)*token_units());
if("" === security_amount_input.value){
security_amount_input.value =
parseFloat(receive_amount_input.value) * 0.1
.toString();
};
var d = new Date();
var hours = parseFloat(hours_input.value, 10);
if(hours > (24*7)){
display.innerHTML = "you cannot make a trade that needs to wait more than a week to run the oracle.";
return(0);
};
d.setTime(d.getTime() +
(hours * 60 * 60 * 1000));
var date = d.toUTCString();
var date = date.slice(5, 22).concat(" GMT");
var Source = ZERO;
var SourceType = 0;
var block_height = headers_object.top()[1];
var oracleStartHeight = block_height;
var blockchain = other_blockchain_input.value;
var ticker = ticker_input.value;
var amount = spend_amount_input.value;
var blocks_till_expires =
parseInt(blocks_till_expires_text.value, 10);
var addressTimeout = blocks_till_expires + block_height;
var reusable_settings = buy_veo_contract.
reusable_settings(
oracleStartHeight, blockchain,
amount, ticker, date);
var salt = btoa(random_cid(32));
var TID = swaps.id_maker(keys.pub(), salt);
var settings = buy_veo_contract.
settings(
reusable_settings, addressTimeout,
1, TID);
var amount2 = Math.round(parseFloat(security_amount_input.value, 10)*token_units());
//the swap offer
var contract_bytes = buy_veo_contract.
contract1bytes(settings);
var cid = buy_veo_contract.
make_cid(contract_bytes, 2, ZERO, 0);
var offer = buy_veo_contract.buy_veo_offer(
blocks_till_expires,
amount2, amount1,
cid, salt);
var offer99 = swaps.offer_99(
swaps.unpack(offer));
//this is the contract data we teach the p2p derivatives server.
var Contract = [
"contract", cid, Source, SourceType,
addressTimeout, oracleStartHeight,
btoa(blockchain), btoa(amount),
btoa(ticker), btoa(date),
TID, 0];
var contract1bytes = await buy_veo_contract.contract_to_1bytes(Contract);
var cid2 = buy_veo_contract.make_cid(contract1bytes, 2, ZERO, 0);
if(!(cid === cid2)){
console.log("made bad contract");
console.log(Contract);
return(0);
};
const my_acc = await rpc.apost(["account", keys.pub()]);
if(my_acc === 0){
display.innerHTML = "Load your private key first.";
return(0);
};
if(my_acc[1] < amount2){
display.innerHTML = "Not enough VEO to make this offer.";
return(0);
};
var nonce = my_acc[2];
const x = await rpc.apost(["add", 4, Contract], IP, 8090);
if(!(x === cid)){
console.log("bad cid produced");
return(0);
};
apost_offer(display, IP, offer, offer99);
refresh();
};
var refresh_button = button_maker2("refresh available actions", refresh);
div.appendChild(br());
div.appendChild(refresh_button);
div.appendChild(br());
div.appendChild(br());
var lists_div = document.createElement("div");
div.appendChild(lists_div);
/*
normal
=========
Alice offers to sell BTC, and she offers to sell her shares for 99% of their max value.
Bob accepts and gives his address to receive BTC, and makes an offer to sell his shares for 99% of their value.
Alice sends the bitcoin.
Bob buys the winning shares for 99% of their value.
Alice has type 2, Bob has type 1.
no delivery address
=======
Alice offers to sell BTC, and she offers to sell her shares for 99% of their max value.
Bob accepts, locking in his veo.
After waiting a delay, Alice resolves the contract and withdraws all Bob's veo, or an untrusted third party buys Alice's winning shares and does it for her.
no btc delivery
======
Alice offers to sell BTC, and she offers to sell her shares for 99% of their max value.
Bob accepts and gives his address to receive BTC, and makes an offer to sell his shares for 99% of their value.
Alice didn't deliver the BTC, so an untrusted third party buys Bob's winning shares, they create the oracle and get the money.
*/
async function refresh(){
var temp_div = document.createElement("div");
lists_div.innerHTML = "