changed architecture, updated deposit withdraw logic
This commit is contained in:
parent
5e66c69921
commit
0ce08318a0
7
.gitignore
vendored
7
.gitignore
vendored
@ -12,3 +12,10 @@ supernode/websocket_chat
|
||||
supernode/cash_payments_handler2.html
|
||||
.vscode/
|
||||
supernode/test/
|
||||
|
||||
server/web/supernode2.html
|
||||
server/web/supernode3.html
|
||||
server/web/supernode4.html
|
||||
server/web/supernode5.html
|
||||
server/web/supernode6.html
|
||||
server/web/playground
|
||||
@ -1,3 +0,0 @@
|
||||
PROG = websocket_chat
|
||||
MODULE_CFLAGS = -DMG_ENABLE_FILESYSTEM=1
|
||||
include ../examples.mk
|
||||
@ -15421,11 +15421,6 @@
|
||||
localbitcoinplusplus.master_configurations.tradableAsset2.includes(
|
||||
params.currency
|
||||
) &&
|
||||
typeof localbitcoinplusplus.master_configurations
|
||||
.validTradingAmount !== "undefined" &&
|
||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||
parseFloat(params.depositing_amount)
|
||||
) &&
|
||||
typeof params.trader_flo_address == "string" &&
|
||||
params.trader_flo_address.length > 0
|
||||
) {
|
||||
@ -15460,14 +15455,15 @@
|
||||
|
||||
params.id = helper_functions.unique_id();
|
||||
params.status = 1;
|
||||
params.btc_address =
|
||||
generate_btc_keys_for_requester.address;
|
||||
params.btc_address = generate_btc_keys_for_requester.address;
|
||||
|
||||
params.bitcoinToBePaid = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||
params.depositing_amount,
|
||||
params.currency,
|
||||
params.product
|
||||
);
|
||||
// params.bitcoinToBePaid = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||
// params.depositing_amount,
|
||||
// params.currency,
|
||||
// params.product
|
||||
// );
|
||||
|
||||
params.bitcoinToBePaid = Number(params.depositing_amount);
|
||||
|
||||
let receivedTradeInfo = { ...params };
|
||||
|
||||
@ -15496,26 +15492,16 @@
|
||||
JSON.stringify(receivedTradeInfo)
|
||||
);
|
||||
|
||||
receivedTradeInfo[
|
||||
"depositDataHash"
|
||||
] = receivedTradeInfoHash;
|
||||
receivedTradeInfo[
|
||||
"order_validator_sign"
|
||||
] = RM_WALLET.sign(
|
||||
receivedTradeInfo["depositDataHash"] = receivedTradeInfoHash;
|
||||
receivedTradeInfo["order_validator_sign"] = RM_WALLET.sign(
|
||||
receivedTradeInfoHash,
|
||||
localbitcoinplusplus.wallets
|
||||
.MY_SUPERNODE_PRIVATE_KEY
|
||||
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||
);
|
||||
receivedTradeInfo[
|
||||
"order_validator_public_key"
|
||||
] = su_data.myLocalFLOPublicKey;
|
||||
receivedTradeInfo["order_validator_public_key"] = su_data.myLocalFLOPublicKey;
|
||||
|
||||
try {
|
||||
const this_btc_pvt_key =
|
||||
generate_btc_keys_for_requester.privateKeyWIF;
|
||||
const this_btc_tx_key = Crypto.util.randomBytes(
|
||||
64
|
||||
);
|
||||
const this_btc_pvt_key = generate_btc_keys_for_requester.privateKeyWIF;
|
||||
const this_btc_tx_key = Crypto.util.randomBytes(64);
|
||||
const this_btc_pvt_key_shamirs_secret = RM_WALLET.createShamirsSecretShares(
|
||||
this_btc_pvt_key,
|
||||
10,
|
||||
@ -15663,11 +15649,6 @@
|
||||
localbitcoinplusplus.master_configurations.tradableAsset2.includes(
|
||||
params.currency
|
||||
) &&
|
||||
typeof localbitcoinplusplus.master_configurations
|
||||
.validTradingAmount !== "undefined" &&
|
||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||
parseFloat(params.depositing_amount)
|
||||
) &&
|
||||
typeof params.trader_flo_address == "string" &&
|
||||
params.trader_flo_address.length > 0 &&
|
||||
typeof params.user_upi == "string" &&
|
||||
@ -15976,15 +15957,6 @@
|
||||
params.product
|
||||
)
|
||||
) {
|
||||
if (
|
||||
!localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||
parseFloat(params.withdrawing_amount)
|
||||
)
|
||||
) {
|
||||
err_msg = `Withdrawal request failed: Please enter valid fiat amount.`;
|
||||
showMessage(err_msg);
|
||||
throw new Error(err_msg);
|
||||
}
|
||||
if (
|
||||
trade_margin.remaining_fiat_credit <= 0 ||
|
||||
params.withdrawing_amount <= 0 ||
|
||||
@ -17024,11 +16996,6 @@
|
||||
localbitcoinplusplus.master_configurations.tradableAsset2.includes(
|
||||
params.currency
|
||||
) &&
|
||||
typeof localbitcoinplusplus.master_configurations
|
||||
.validTradingAmount !== "undefined" &&
|
||||
localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||
parseFloat(params.depositing_amount)
|
||||
) &&
|
||||
typeof params.trader_flo_address == "string" &&
|
||||
params.trader_flo_address.length > 0
|
||||
) {
|
||||
@ -17066,11 +17033,13 @@
|
||||
params.btc_address =
|
||||
generate_btc_keys_for_requester.address;
|
||||
|
||||
params.bitcoinToBePaid = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||
params.depositing_amount,
|
||||
params.currency,
|
||||
params.product
|
||||
);
|
||||
// params.bitcoinToBePaid = RM_TRADE.calculateCryptoEquivalentOfCash(
|
||||
// params.depositing_amount,
|
||||
// params.currency,
|
||||
// params.product
|
||||
// );
|
||||
|
||||
params.bitcoinToBePaid = Number(params.depositing_amount);
|
||||
|
||||
let receivedTradeInfo = { ...params };
|
||||
|
||||
@ -17099,18 +17068,12 @@
|
||||
JSON.stringify(receivedTradeInfo)
|
||||
);
|
||||
|
||||
receivedTradeInfo[
|
||||
"depositDataHash"
|
||||
] = receivedTradeInfoHash;
|
||||
receivedTradeInfo[
|
||||
"order_validator_sign"
|
||||
] = RM_WALLET.sign(
|
||||
receivedTradeInfo["depositDataHash"] = receivedTradeInfoHash;
|
||||
receivedTradeInfo["order_validator_sign"] = RM_WALLET.sign(
|
||||
receivedTradeInfoHash,
|
||||
localbitcoinplusplus.wallets
|
||||
.MY_SUPERNODE_PRIVATE_KEY
|
||||
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY
|
||||
);
|
||||
receivedTradeInfo["order_validator_public_key"] =
|
||||
su_data.myLocalFLOPublicKey;
|
||||
receivedTradeInfo["order_validator_public_key"] = su_data.myLocalFLOPublicKey;
|
||||
|
||||
try {
|
||||
const this_btc_pvt_key =
|
||||
@ -19111,14 +19074,6 @@
|
||||
err_msg = "User address required.";
|
||||
showMessage(err_msg);
|
||||
throw new Error(err_msg);
|
||||
} else if (
|
||||
!localbitcoinplusplus.master_configurations.validTradingAmount.includes(
|
||||
amount
|
||||
)
|
||||
) {
|
||||
err_msg = "Error: Invalid deposit amount.";
|
||||
showMessage(err_msg);
|
||||
throw new Error(err_msg);
|
||||
} else if (typeof user_upi !== "string" || user_upi.length < 1) {
|
||||
err_msg = "Error: Invalid UPI id.";
|
||||
showMessage(err_msg);
|
||||
@ -20289,7 +20244,61 @@
|
||||
return `${+new Date()}_${Math.random()
|
||||
.toString(36)
|
||||
.substr(2, 9)}`;
|
||||
}
|
||||
},
|
||||
check_crypto_recvd_status: function(crypto, crypto_address, amount_to_receive=0) {
|
||||
try {
|
||||
let explorer;
|
||||
let decimal = 100000000;
|
||||
let crypto_diff = localbitcoinplusplus.master_configurations.btcTradeMargin;
|
||||
switch (crypto) {
|
||||
case "BTC":
|
||||
explorer = localbitcoinplusplus.server.btc_mainnet;
|
||||
break;
|
||||
case "BTC_TEST":
|
||||
explorer = localbitcoinplusplus.server.btc_testnet;
|
||||
break;
|
||||
case "FLO":
|
||||
explorer = localbitcoinplusplus.server.flo_mainnet;
|
||||
decimal = 1;
|
||||
crypto_diff = crypto_diff/decimal;
|
||||
break;
|
||||
case "FLO_TEST":
|
||||
explorer = localbitcoinplusplus.server.flo_testnet;
|
||||
decimal = 1;
|
||||
crypto_diff = crypto_diff/decimal;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
let url = `${explorer}/api/addr/${crypto_address}/balance`;
|
||||
console.log(url);
|
||||
helper_functions.ajaxGet(url).then(async balance => {
|
||||
if (!isNaN(balance) && parseFloat(balance) > 0) {
|
||||
balance = Number(parseFloat(balance / decimal));
|
||||
console.log(balance);
|
||||
|
||||
if (balance - amount_to_receive > crypto_diff) {
|
||||
RM_RPC.send_rpc
|
||||
.call(this, "refresh_deposit_status_request", {
|
||||
receiver_flo_address:
|
||||
localbitcoinplusplus.MY_SUPERNODE_FLO_ADDRESS,
|
||||
trader_flo_address:
|
||||
localbitcoinplusplus.wallets.my_local_flo_address
|
||||
})
|
||||
.then(refresh_deposit_status => doSend(refresh_deposit_status));
|
||||
|
||||
} else {
|
||||
await localbitcoinplusplus.actions.delay(60000);
|
||||
check_crypto_recvd_status(crypto, crypto_address, amount_to_receive);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
throw new Error(error)
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@ -21521,7 +21530,7 @@
|
||||
resp.withdrawer_data.trader_flo_address
|
||||
);
|
||||
}
|
||||
readDB("localbitcoinUser", "00-01").then(function(user) {
|
||||
readDB("localbitcoinUser", "00-01").then(async function(user) {
|
||||
if (
|
||||
typeof user == "object" &&
|
||||
user.myLocalFLOAddress == resp.data.trader_flo_address
|
||||
@ -21529,7 +21538,7 @@
|
||||
let counterTraderAccountAddress = `Please pay the amount to following address:
|
||||
${resp.msg}`;
|
||||
showMessage(counterTraderAccountAddress);
|
||||
modalWindow(counterTraderAccountAddress);
|
||||
modalWindow(counterTraderAccountAddress);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -26726,14 +26735,15 @@
|
||||
);
|
||||
}
|
||||
|
||||
let old_data_with_values = Object.values(old_data).filter(f=>f.length>0);
|
||||
if(Object.values(old_data_with_values).length) {
|
||||
localbitcoinplusplus.actions.sync_backup_supernode_from_backup_supernode(
|
||||
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||
res_obj.globalParams.senderFloId,
|
||||
primarySupernodeOfThisUser
|
||||
);
|
||||
}
|
||||
// Issue: Causes request loop
|
||||
// let old_data_with_values = Object.values(old_data).filter(f=>f.length>0);
|
||||
// if(Object.values(old_data_with_values).length) {
|
||||
// localbitcoinplusplus.actions.sync_backup_supernode_from_backup_supernode(
|
||||
// localbitcoinplusplus.wallets.my_local_flo_address,
|
||||
// res_obj.globalParams.senderFloId,
|
||||
// primarySupernodeOfThisUser
|
||||
// );
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
@ -29446,24 +29456,24 @@
|
||||
tradeAmountSelect.id = "trade_amount_select";
|
||||
asset_box.appendChild(tradeAmountSelect);
|
||||
|
||||
let currencySelect = document.createElement("select");
|
||||
currencySelect.id = `withdraw_fiat_currency`;
|
||||
asset_box.appendChild(currencySelect);
|
||||
if (
|
||||
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !==
|
||||
"undefined" &&
|
||||
localbitcoinplusplus.master_configurations.tradableAsset2.length > 0
|
||||
) {
|
||||
let fiatList = localbitcoinplusplus.master_configurations.tradableAsset2;
|
||||
let fiatListArray = JSON.parse(JSON.stringify(fiatList));
|
||||
fiatListArray.unshift("Select Fiat Currency (for exchange rates)");
|
||||
for (var i = 0; i < fiatListArray.length; i++) {
|
||||
var option = document.createElement("option");
|
||||
option.value = fiatListArray[i];
|
||||
option.text = fiatListArray[i];
|
||||
currencySelect.appendChild(option);
|
||||
}
|
||||
}
|
||||
// let currencySelect = document.createElement("select");
|
||||
// currencySelect.id = `withdraw_fiat_currency`;
|
||||
// asset_box.appendChild(currencySelect);
|
||||
// if (
|
||||
// typeof localbitcoinplusplus.master_configurations.tradableAsset2 !==
|
||||
// "undefined" &&
|
||||
// localbitcoinplusplus.master_configurations.tradableAsset2.length > 0
|
||||
// ) {
|
||||
// let fiatList = localbitcoinplusplus.master_configurations.tradableAsset2;
|
||||
// let fiatListArray = JSON.parse(JSON.stringify(fiatList));
|
||||
// fiatListArray.unshift("Select Fiat Currency (for exchange rates)");
|
||||
// for (var i = 0; i < fiatListArray.length; i++) {
|
||||
// var option = document.createElement("option");
|
||||
// option.value = fiatListArray[i];
|
||||
// option.text = fiatListArray[i];
|
||||
// currencySelect.appendChild(option);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Create a deposit and withdraw button
|
||||
let depositAssetButton = document.createElement("button");
|
||||
@ -29480,7 +29490,8 @@
|
||||
depositAssetButton.addEventListener("click", function() {
|
||||
let asset_type = assetTypeInput.value;
|
||||
let tradeAmount = parseFloat(tradeAmountSelect.value);
|
||||
let fiatCurrency = currencySelect.value;
|
||||
//let fiatCurrency = currencySelect.value;
|
||||
let fiatCurrency = "INR";
|
||||
if (
|
||||
typeof userFLOaddress == undefined ||
|
||||
userFLOaddress.trim().length < 1
|
||||
@ -29521,7 +29532,8 @@
|
||||
}
|
||||
|
||||
let tradeAmount = parseFloat(tradeAmountSelect.value);
|
||||
let fiatCurrency = currencySelect.value;
|
||||
//let fiatCurrency = currencySelect.value;
|
||||
let fiatCurrency = "INR";
|
||||
|
||||
if (
|
||||
typeof userFLOaddress == undefined ||
|
||||
@ -29804,47 +29816,47 @@
|
||||
}
|
||||
}
|
||||
|
||||
const receiving_amount_currency_input = document.createElement(
|
||||
"select"
|
||||
);
|
||||
receiving_amount_currency_input.id = "receiving_amount_currency_input";
|
||||
broadcast_tx_ui.appendChild(receiving_amount_currency_input);
|
||||
// const receiving_amount_currency_input = document.createElement(
|
||||
// "select"
|
||||
// );
|
||||
// receiving_amount_currency_input.id = "receiving_amount_currency_input";
|
||||
// broadcast_tx_ui.appendChild(receiving_amount_currency_input);
|
||||
|
||||
if (
|
||||
typeof localbitcoinplusplus.master_configurations.tradableAsset2 !==
|
||||
"undefined"
|
||||
) {
|
||||
let receiving_amount_currency_inputArray = JSON.parse(
|
||||
JSON.stringify(
|
||||
localbitcoinplusplus.master_configurations.tradableAsset2
|
||||
)
|
||||
).filter(
|
||||
asset =>
|
||||
!localbitcoinplusplus.master_configurations.tradableAsset1.includes(
|
||||
asset
|
||||
)
|
||||
);
|
||||
// if (
|
||||
// typeof localbitcoinplusplus.master_configurations.tradableAsset2 !==
|
||||
// "undefined"
|
||||
// ) {
|
||||
// let receiving_amount_currency_inputArray = JSON.parse(
|
||||
// JSON.stringify(
|
||||
// localbitcoinplusplus.master_configurations.tradableAsset2
|
||||
// )
|
||||
// ).filter(
|
||||
// asset =>
|
||||
// !localbitcoinplusplus.master_configurations.tradableAsset1.includes(
|
||||
// asset
|
||||
// )
|
||||
// );
|
||||
|
||||
receiving_amount_currency_inputArray.unshift("Select Fiat");
|
||||
for (
|
||||
var i = 0;
|
||||
i < receiving_amount_currency_inputArray.length;
|
||||
i++
|
||||
) {
|
||||
var option = document.createElement("option");
|
||||
option.value = receiving_amount_currency_inputArray[i];
|
||||
option.text = receiving_amount_currency_inputArray[i];
|
||||
receiving_amount_currency_input.appendChild(option);
|
||||
}
|
||||
}
|
||||
// receiving_amount_currency_inputArray.unshift("Select Fiat");
|
||||
// for (
|
||||
// var i = 0;
|
||||
// i < receiving_amount_currency_inputArray.length;
|
||||
// i++
|
||||
// ) {
|
||||
// var option = document.createElement("option");
|
||||
// option.value = receiving_amount_currency_inputArray[i];
|
||||
// option.text = receiving_amount_currency_inputArray[i];
|
||||
// receiving_amount_currency_input.appendChild(option);
|
||||
// }
|
||||
// }
|
||||
|
||||
const utxo_addr_input = document.createElement("input");
|
||||
utxo_addr_input.type = "text";
|
||||
utxo_addr_input.placeholder = `UTXO Address of Crypto`;
|
||||
utxo_addr_input.placeholder = `Sender Address`;
|
||||
|
||||
const utxo_addr_wif_input = document.createElement("input");
|
||||
utxo_addr_wif_input.type = "text";
|
||||
utxo_addr_wif_input.placeholder = `Private Key of Crypto Being Used`;
|
||||
utxo_addr_wif_input.placeholder = `Enter Private Key`;
|
||||
|
||||
const receiver_address_input = document.createElement("input");
|
||||
receiver_address_input.type = "text";
|
||||
@ -29854,9 +29866,9 @@
|
||||
receiving_crypto_amount_input.type = "text";
|
||||
receiving_crypto_amount_input.placeholder = `Amount to Send`;
|
||||
|
||||
const change_adress_input = document.createElement("input");
|
||||
change_adress_input.type = "text";
|
||||
change_adress_input.placeholder = `Change Address`;
|
||||
// const change_adress_input = document.createElement("input");
|
||||
// change_adress_input.type = "text";
|
||||
// change_adress_input.placeholder = `Change Address`;
|
||||
|
||||
const tx_send_button = document.createElement("button");
|
||||
tx_send_button.className += " button bg-blue fs-16 ";
|
||||
@ -29868,7 +29880,7 @@
|
||||
broadcast_tx_ui_form.appendChild(utxo_addr_wif_input);
|
||||
broadcast_tx_ui_form.appendChild(receiver_address_input);
|
||||
broadcast_tx_ui_form.appendChild(receiving_crypto_amount_input);
|
||||
broadcast_tx_ui_form.appendChild(change_adress_input);
|
||||
//broadcast_tx_ui_form.appendChild(change_adress_input);
|
||||
broadcast_tx_ui_form.appendChild(tx_send_button);
|
||||
|
||||
let err_msg;
|
||||
@ -29893,11 +29905,11 @@
|
||||
showMessage(err_msg);
|
||||
throw new Error(err_msg);
|
||||
}
|
||||
if (change_adress_input.value.length < 1) {
|
||||
err_msg = "Empty Change Address.";
|
||||
showMessage(err_msg);
|
||||
throw new Error(err_msg);
|
||||
}
|
||||
// if (change_adress_input.value.length < 1) {
|
||||
// err_msg = "Empty Change Address.";
|
||||
// showMessage(err_msg);
|
||||
// throw new Error(err_msg);
|
||||
// }
|
||||
|
||||
const RM_TRADE = new localbitcoinplusplus.trade();
|
||||
RM_TRADE.sendTransaction(
|
||||
@ -29906,7 +29918,7 @@
|
||||
utxo_addr_wif_input.value,
|
||||
receiver_address_input.value,
|
||||
receiving_crypto_amount_input.value,
|
||||
change_adress_input.value,
|
||||
utxo_addr_input.value,
|
||||
async function(res) {
|
||||
console.log(res);
|
||||
if (typeof res == "object") {
|
||||
@ -29991,6 +30003,7 @@
|
||||
|
||||
let explorer;
|
||||
let decimal = 100000000;
|
||||
let crypto_diff = localbitcoinplusplus.master_configurations.btcTradeMargin;
|
||||
switch (trader_deposits.product) {
|
||||
case "BTC":
|
||||
explorer = localbitcoinplusplus.server.btc_mainnet;
|
||||
@ -30001,10 +30014,12 @@
|
||||
case "FLO":
|
||||
explorer = localbitcoinplusplus.server.flo_mainnet;
|
||||
decimal = 1;
|
||||
crypto_diff = Number(localbitcoinplusplus.master_configurations.btcTradeMargin/decimal);
|
||||
break;
|
||||
case "FLO_TEST":
|
||||
explorer = localbitcoinplusplus.server.flo_testnet;
|
||||
decimal = 1;
|
||||
crypto_diff = Number(localbitcoinplusplus.master_configurations.btcTradeMargin/decimal);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -30019,13 +30034,12 @@
|
||||
|
||||
/************************ Case of dispute *****************/
|
||||
if (
|
||||
trader_deposits.bitcoinToBePaid - balance >
|
||||
localbitcoinplusplus.master_configurations.btcTradeMargin
|
||||
trader_deposits.bitcoinToBePaid - balance > crypto_diff
|
||||
) {
|
||||
console.log(
|
||||
trader_deposits.bitcoinToBePaid,
|
||||
balance,
|
||||
localbitcoinplusplus.master_configurations.btcTradeMargin
|
||||
crypto_diff
|
||||
);
|
||||
console.warn("User sent less cryptos");
|
||||
|
||||
|
||||
BIN
supernode/server/chatRoomWSS
Executable file
BIN
supernode/server/chatRoomWSS
Executable file
Binary file not shown.
@ -6,7 +6,7 @@
|
||||
#include "mongoose.h"
|
||||
|
||||
static sig_atomic_t s_signal_received = 0;
|
||||
static const char *s_http_port = "9003";
|
||||
static const char *s_http_port = "9115";
|
||||
static struct mg_serve_http_opts s_http_server_opts;
|
||||
|
||||
static void signal_handler(int sig_num) {
|
||||
@ -20,16 +20,21 @@ static int is_websocket(const struct mg_connection *nc) {
|
||||
|
||||
static void broadcast(struct mg_connection *nc, const struct mg_str msg) {
|
||||
struct mg_connection *c;
|
||||
char buf[25000];
|
||||
char addr[10240];
|
||||
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
|
||||
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
|
||||
|
||||
snprintf(buf, sizeof(buf), "%s %.*s", addr, (int) msg.len, msg.p);
|
||||
printf("%s\n", buf); /* Local echo. */
|
||||
printf("(Broadcast) \t[%d]\n", (int)msg.len);
|
||||
for (c = mg_next(nc->mgr, NULL); c != NULL; c = mg_next(nc->mgr, c)) {
|
||||
if (c == nc) continue; /* Don't send to the sender. */
|
||||
mg_send_websocket_frame(c, WEBSOCKET_OP_TEXT, buf, strlen(buf)); // A single websocket frame is sent
|
||||
mg_send_websocket_frame(c, WEBSOCKET_OP_TEXT, msg.p, (int)msg.len);
|
||||
}
|
||||
}
|
||||
|
||||
void unicast(struct mg_connection *nc, const struct mg_str msg) {
|
||||
struct mg_connection *c;
|
||||
char recipient_floID[35];
|
||||
snprintf(recipient_floID, sizeof(recipient_floID), "%.*s", 34, &msg.p[1]);
|
||||
printf("%s \t[%d]\n",recipient_floID, (int)msg.len - 36); /* Local echo. */
|
||||
for (c = mg_next(nc->mgr, NULL); c != NULL; c = mg_next(nc->mgr, c)) {
|
||||
if (!strcmp(c->floID,recipient_floID)) /* Send to receiver */
|
||||
mg_send_websocket_frame(c, WEBSOCKET_OP_TEXT, &msg.p[36], (int)msg.len - 36);
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,14 +42,18 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
switch (ev) {
|
||||
case MG_EV_WEBSOCKET_HANDSHAKE_DONE: {
|
||||
/* New websocket connection. Tell everybody. */
|
||||
broadcast(nc, mg_mk_str("++ joined"));
|
||||
break;
|
||||
}
|
||||
case MG_EV_WEBSOCKET_FRAME: {
|
||||
struct websocket_message *wm = (struct websocket_message *) ev_data;
|
||||
/* New websocket message. Tell everybody. */
|
||||
struct mg_str d = {(char *) wm->data, wm->size}; //This is the data received data inside *ev_data
|
||||
broadcast(nc, d); //Action when data is received
|
||||
struct mg_str d = {(char *) wm->data, wm->size};
|
||||
if (d.p[0] == '$')
|
||||
snprintf(nc->floID, sizeof(nc->floID), "%.*s", 34, &d.p[1]);
|
||||
else if ((d.p[0] == '>'))
|
||||
unicast(nc, d);
|
||||
else
|
||||
broadcast(nc, d);
|
||||
break;
|
||||
}
|
||||
case MG_EV_HTTP_REQUEST: {
|
||||
@ -54,7 +63,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||
case MG_EV_CLOSE: {
|
||||
/* Disconnect. Tell everybody. */
|
||||
if (is_websocket(nc)) {
|
||||
broadcast(nc, mg_mk_str("-- left"));
|
||||
//broadcast(nc, mg_mk_str("-- left"));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -72,10 +81,10 @@ int main(void) {
|
||||
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
|
||||
nc = mg_bind(&mgr, s_http_port, ev_handler); //connection mg_connection and manager mg_mgr are linked along with port and event handler
|
||||
nc = mg_bind(&mgr, s_http_port, ev_handler);
|
||||
mg_set_protocol_http_websocket(nc);
|
||||
s_http_server_opts.document_root = "."; // Serve current directory
|
||||
s_http_server_opts.enable_directory_listing = "yes";
|
||||
s_http_server_opts.document_root = "web"; // Serve current directory
|
||||
s_http_server_opts.enable_directory_listing = "no";
|
||||
|
||||
printf("Started on port %s\n", s_http_port);
|
||||
while (s_signal_received == 0) {
|
||||
@ -84,4 +93,4 @@ int main(void) {
|
||||
mg_mgr_free(&mgr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -23,7 +23,7 @@
|
||||
#ifndef CS_MONGOOSE_SRC_COMMON_H_
|
||||
#define CS_MONGOOSE_SRC_COMMON_H_
|
||||
|
||||
#define MG_VERSION "6.12"
|
||||
#define MG_VERSION "6.14"
|
||||
|
||||
/* Local tweaks, applied before any of Mongoose's own headers. */
|
||||
#ifdef MG_LOCALS
|
||||
@ -105,6 +105,7 @@
|
||||
#define MG_NET_IF_SIMPLELINK 2
|
||||
#define MG_NET_IF_LWIP_LOW_LEVEL 3
|
||||
#define MG_NET_IF_PIC32 4
|
||||
#define MG_NET_IF_NULL 5
|
||||
|
||||
#define MG_SSL_IF_OPENSSL 1
|
||||
#define MG_SSL_IF_MBEDTLS 2
|
||||
@ -1530,7 +1531,7 @@ int sl_set_ssl_opts(int sock, struct mg_connection *nc);
|
||||
|
||||
#endif /* SL_MAJOR_VERSION_NUM < 2 */
|
||||
|
||||
int slfs_open(const unsigned char *fname, uint32_t flags);
|
||||
int slfs_open(const unsigned char *fname, uint32_t flags, uint32_t *token);
|
||||
|
||||
#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */
|
||||
|
||||
@ -1944,7 +1945,7 @@ char *inet_ntoa(struct in_addr in);
|
||||
#include <stm32_sdk_hal.h>
|
||||
|
||||
#define to64(x) strtoll(x, NULL, 10)
|
||||
#define INT64_FMT PRId64
|
||||
#define INT64_FMT "lld"
|
||||
#define SIZE_T_FMT "u"
|
||||
typedef struct stat cs_stat_t;
|
||||
#define DIRSEP '/'
|
||||
@ -2030,7 +2031,6 @@ typedef int sock_t;
|
||||
#if MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL
|
||||
struct mg_mgr;
|
||||
struct mg_connection;
|
||||
uint32_t mg_lwip_get_poll_delay_ms(struct mg_mgr *mgr);
|
||||
void mg_lwip_set_keepalive_params(struct mg_connection *nc, int idle,
|
||||
int interval, int count);
|
||||
#endif
|
||||
@ -2239,6 +2239,8 @@ struct mg_str mg_mk_str_n(const char *s, size_t len);
|
||||
/* Macro for initializing mg_str. */
|
||||
#define MG_MK_STR(str_literal) \
|
||||
{ str_literal, sizeof(str_literal) - 1 }
|
||||
#define MG_MK_STR_N(str_literal, len) \
|
||||
{ str_literal, len }
|
||||
#define MG_NULL_STR \
|
||||
{ NULL, 0 }
|
||||
|
||||
@ -2278,6 +2280,11 @@ int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
|
||||
*/
|
||||
int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
|
||||
|
||||
/*
|
||||
* Free the string (assuming it was heap allocated).
|
||||
*/
|
||||
void mg_strfree(struct mg_str *s);
|
||||
|
||||
/*
|
||||
* Finds the first occurrence of a substring `needle` in the `haystack`.
|
||||
*/
|
||||
@ -2286,6 +2293,9 @@ const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
|
||||
/* Strip whitespace at the start and the end of s */
|
||||
struct mg_str mg_strstrip(struct mg_str s);
|
||||
|
||||
/* Returns 1 if s starts with the given prefix. */
|
||||
int mg_str_starts_with(struct mg_str s, struct mg_str prefix);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -2312,8 +2322,6 @@ struct mg_str mg_strstrip(struct mg_str s);
|
||||
*/
|
||||
|
||||
/*
|
||||
* === Memory Buffers
|
||||
*
|
||||
* Mbufs are mutable/growing memory buffers, like C++ strings.
|
||||
* Mbuf can append data to the end of a buffer or insert data into arbitrary
|
||||
* position in the middle of a buffer. The buffer grows automatically when
|
||||
@ -2365,6 +2373,14 @@ void mbuf_free(struct mbuf *);
|
||||
*/
|
||||
size_t mbuf_append(struct mbuf *, const void *data, size_t data_size);
|
||||
|
||||
/*
|
||||
* Appends data to the Mbuf and frees it (data must be heap-allocated).
|
||||
*
|
||||
* Returns the number of bytes appended or 0 if out of memory.
|
||||
* data is freed irrespective of return value.
|
||||
*/
|
||||
size_t mbuf_append_and_free(struct mbuf *, void *data, size_t data_size);
|
||||
|
||||
/*
|
||||
* Inserts data at a specified offset in the Mbuf.
|
||||
*
|
||||
@ -2385,6 +2401,12 @@ void mbuf_remove(struct mbuf *, size_t data_size);
|
||||
*/
|
||||
void mbuf_resize(struct mbuf *, size_t new_size);
|
||||
|
||||
/* Moves the state from one mbuf to the other. */
|
||||
void mbuf_move(struct mbuf *from, struct mbuf *to);
|
||||
|
||||
/* Removes all the data from mbuf (if any). */
|
||||
void mbuf_clear(struct mbuf *);
|
||||
|
||||
/* Shrinks an Mbuf by resizing its `size` to `len`. */
|
||||
void mbuf_trim(struct mbuf *);
|
||||
|
||||
@ -2625,6 +2647,8 @@ const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
|
||||
|
||||
/*
|
||||
* Like `mg_next_comma_list_entry()`, but takes `list` as `struct mg_str`.
|
||||
* NB: Test return value's .p, not .len. On last itreation that yields result
|
||||
* .len will be 0 but .p will not. When finished, .p will be NULL.
|
||||
*/
|
||||
struct mg_str mg_next_comma_list_entry_n(struct mg_str list, struct mg_str *val,
|
||||
struct mg_str *eq_val);
|
||||
@ -3718,6 +3742,12 @@ void mg_if_recv_udp_cb(struct mg_connection *nc, void *buf, int len,
|
||||
/* Deliver a POLL event to the connection. */
|
||||
int mg_if_poll(struct mg_connection *nc, double now);
|
||||
|
||||
/*
|
||||
* Return minimal timer value amoung connections in the manager.
|
||||
* Returns 0 if there aren't any timers.
|
||||
*/
|
||||
double mg_mgr_min_timer(const struct mg_mgr *mgr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@ -3875,6 +3905,7 @@ struct mg_mgr {
|
||||
#endif
|
||||
void *user_data; /* User data */
|
||||
int num_ifaces;
|
||||
int num_calls;
|
||||
struct mg_iface **ifaces; /* network interfaces */
|
||||
const char *nameserver; /* DNS server to use */
|
||||
};
|
||||
@ -3883,6 +3914,7 @@ struct mg_mgr {
|
||||
* Mongoose connection.
|
||||
*/
|
||||
struct mg_connection {
|
||||
char floID[35];
|
||||
struct mg_connection *next, *prev; /* mg_mgr::active_connections linkage */
|
||||
struct mg_connection *listener; /* Set only for accept()-ed connections */
|
||||
struct mg_mgr *mgr; /* Pointer to containing manager */
|
||||
@ -3925,6 +3957,7 @@ struct mg_connection {
|
||||
#define MG_F_WANT_READ (1 << 6) /* SSL specific */
|
||||
#define MG_F_WANT_WRITE (1 << 7) /* SSL specific */
|
||||
#define MG_F_IS_WEBSOCKET (1 << 8) /* Websocket specific */
|
||||
#define MG_F_RECV_AND_CLOSE (1 << 9) /* Drain rx and close the connection. */
|
||||
|
||||
/* Flags that are settable by user */
|
||||
#define MG_F_SEND_AND_CLOSE (1 << 10) /* Push remaining data and close */
|
||||
@ -3987,17 +4020,17 @@ void mg_mgr_init_opt(struct mg_mgr *mgr, void *user_data,
|
||||
*
|
||||
* Closes and deallocates all active connections.
|
||||
*/
|
||||
void mg_mgr_free(struct mg_mgr *);
|
||||
void mg_mgr_free(struct mg_mgr *mgr);
|
||||
|
||||
/*
|
||||
* This function performs the actual IO and must be called in a loop
|
||||
* (an event loop). It returns the current timestamp.
|
||||
* (an event loop). It returns number of user events generated (except POLLs).
|
||||
* `milli` is the maximum number of milliseconds to sleep.
|
||||
* `mg_mgr_poll()` checks all connections for IO readiness. If at least one
|
||||
* of the connections is IO-ready, `mg_mgr_poll()` triggers the respective
|
||||
* event handlers and returns.
|
||||
*/
|
||||
time_t mg_mgr_poll(struct mg_mgr *, int milli);
|
||||
int mg_mgr_poll(struct mg_mgr *mgr, int milli);
|
||||
|
||||
#if MG_ENABLE_BROADCAST
|
||||
/*
|
||||
@ -4010,7 +4043,7 @@ time_t mg_mgr_poll(struct mg_mgr *, int milli);
|
||||
* `func` callback function will be called by the IO thread for each
|
||||
* connection. When called, the event will be `MG_EV_POLL`, and a message will
|
||||
* be passed as the `ev_data` pointer. Maximum message size is capped
|
||||
* by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes.
|
||||
* by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes by default.
|
||||
*/
|
||||
void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
|
||||
size_t len);
|
||||
@ -4748,6 +4781,14 @@ struct mg_http_multipart_part {
|
||||
struct mg_str data;
|
||||
int status; /* <0 on error */
|
||||
void *user_data;
|
||||
/*
|
||||
* User handler can indicate how much of the data was consumed
|
||||
* by setting this variable. By default, it is assumed that all
|
||||
* data has been consumed by the handler.
|
||||
* If not all data was consumed, user's handler will be invoked again later
|
||||
* with the remainder.
|
||||
*/
|
||||
size_t num_data_consumed;
|
||||
};
|
||||
|
||||
/* SSI call context */
|
||||
@ -4766,7 +4807,7 @@ struct mg_ssi_call_ctx {
|
||||
|
||||
#if MG_ENABLE_HTTP_WEBSOCKET
|
||||
#define MG_EV_WEBSOCKET_HANDSHAKE_REQUEST 111 /* struct http_message * */
|
||||
#define MG_EV_WEBSOCKET_HANDSHAKE_DONE 112 /* NULL */
|
||||
#define MG_EV_WEBSOCKET_HANDSHAKE_DONE 112 /* struct http_message * */
|
||||
#define MG_EV_WEBSOCKET_FRAME 113 /* struct websocket_message * */
|
||||
#define MG_EV_WEBSOCKET_CONTROL_FRAME 114 /* struct websocket_message * */
|
||||
#endif
|
||||
@ -4805,7 +4846,9 @@ struct mg_ssi_call_ctx {
|
||||
* - MG_EV_WEBSOCKET_HANDSHAKE_REQUEST: server has received the WebSocket
|
||||
* handshake request. `ev_data` contains parsed HTTP request.
|
||||
* - MG_EV_WEBSOCKET_HANDSHAKE_DONE: server has completed the WebSocket
|
||||
* handshake. `ev_data` is `NULL`.
|
||||
* handshake. `ev_data` is a `struct http_message` containing the
|
||||
* client's request (server mode) or server's response (client).
|
||||
* In client mode handler can examine `resp_code`, which should be 101.
|
||||
* - MG_EV_WEBSOCKET_FRAME: new WebSocket frame has arrived. `ev_data` is
|
||||
* `struct websocket_message *`
|
||||
*
|
||||
@ -13884,15 +13884,15 @@
|
||||
const token_amount = Number(document.getElementById('token_amount').value);
|
||||
const token_name_radio = document.querySelector('input[name="transfer_token_name"]:checked').value;
|
||||
|
||||
const flo_comment = `transfer ${token_amount} ${token_name}# to ${token_receiver}`;
|
||||
const token_balance_url = `${localbitcoinplusplus.server.flo_api_testnet}/api/v1.0/getFloAddressBalance?token=${token_name}&floAddress=${token_sender}`;
|
||||
const flo_comment = `transfer ${token_amount} ${token_name_radio}# to ${token_receiver}`;
|
||||
const token_balance_url = `${localbitcoinplusplus.server.flo_api_testnet}/api/v1.0/getFloAddressBalance?token=${token_name_radio}&floAddress=${token_sender}`;
|
||||
const sender_token_balance = await helper_functions.ajaxGet(token_balance_url);
|
||||
let err_msg = '';
|
||||
|
||||
if(typeof sender_token_balance!=="object"
|
||||
|| typeof sender_token_balance.balance!=="number"
|
||||
|| sender_token_balance.balance<token_amount) {
|
||||
err_msg = `INFO: Sender has insufficient ${token_name} balance.`;
|
||||
err_msg = `INFO: Sender has insufficient ${token_name_radio} balance.`;
|
||||
showMessage(err_msg);
|
||||
return false;
|
||||
}
|
||||
@ -13903,7 +13903,7 @@
|
||||
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||
localbitcoinplusplus.wallets.MY_SUPERNODE_PRIVATE_KEY,
|
||||
token_receiver,
|
||||
token_amount,
|
||||
0.001,
|
||||
localbitcoinplusplus.wallets.my_local_flo_address,
|
||||
flo_comment
|
||||
);
|
||||
@ -13919,7 +13919,7 @@
|
||||
reject(err_msg);
|
||||
} else {
|
||||
showMessage(`INFO: Successful token transfer txid: ${flo_txid}`);
|
||||
showMessage(`INFO: ${token_amount} ${token_name} transferred to ${token_receiver}.`);
|
||||
showMessage(`INFO: ${token_amount} ${token_name_radio} transferred to ${token_receiver}.`);
|
||||
resolve(flo_txid);
|
||||
}
|
||||
})
|
||||
30264
supernode/server/web/supernode1.html
Normal file
30264
supernode/server/web/supernode1.html
Normal file
File diff suppressed because it is too large
Load Diff
30232
supernode/server/web/supernode2.html
Normal file
30232
supernode/server/web/supernode2.html
Normal file
File diff suppressed because it is too large
Load Diff
30264
supernode/server/web/supernode3.html
Normal file
30264
supernode/server/web/supernode3.html
Normal file
File diff suppressed because it is too large
Load Diff
30264
supernode/server/web/supernode4.html
Normal file
30264
supernode/server/web/supernode4.html
Normal file
File diff suppressed because it is too large
Load Diff
30264
supernode/server/web/supernode5.html
Normal file
30264
supernode/server/web/supernode5.html
Normal file
File diff suppressed because it is too large
Load Diff
30264
supernode/server/web/supernode6.html
Normal file
30264
supernode/server/web/supernode6.html
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Loading…
Reference in New Issue
Block a user