Skip to content

Commit

Permalink
Merge branch 'btc_config' into 'develop'
Browse files Browse the repository at this point in the history
Btc config

See merge request in3/c/in3-core!205
  • Loading branch information
simon-jentzsch committed Apr 8, 2020
2 parents 25d711b + 4dd1ba9 commit 99565a0
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 12 deletions.
10 changes: 5 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"program": "${workspaceFolder}/build/bin/in3",
"cwd": "${workspaceFolder}",
"args": [
"call",
"-to",
"0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f",
"nodes(uint256):(string,uint,uint64,uint192,uint64,address,bytes32)",
"0"
"-c",
"btc",
"getblock",
"000000000000000000103b2395f6cd94221b10d02eb9be5850303c0534307220",
"-debug"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ option(ETH_BASIC "build basic eth verification.(all rpc-calls except eth_call)"
option(ETH_FULL "build full eth verification.(including eth_call)" ON)
option(IPFS "build IPFS verification" ON)
option(COLOR "Enable color codes for debug" ON)
option(BTC "if true, the bitcoin verifiers will be build" OFF)
option(BTC "if true, the bitcoin verifiers will be build" ON)
option(IN3API "build the USN-API which offer better interfaces and additional functions on top of the pure verification" ON)
option(USE_PRECOMPUTED_EC "if true the secp256k1 curve uses precompiled tables to boost performance. turning this off makes ecrecover slower, but saves about 37kb." ON)
option(ERR_MSG "if set human readable error messages will be inculded in th executable, otherwise only the error code is used. (saves about 19kB)" ON)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ decentralized and secure network of remote nodes and clients which are able to v
fast access to blockchain for a large number of low-performance IoT, mobile devices, and web applications.


![in3](docs/in3_image.png)
![in3](c/docs/in3_image.png)

A more detailed explanation of in3 can be found [here](https://in3.readthedocs.io/en/latest/intro.html).

Expand Down
8 changes: 6 additions & 2 deletions c/src/cmd/in3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,12 @@ int main(int argc, char* argv[]) {
uint32_t calc_weight = in3_node_calculate_weight(weight, node->capacity, now);
char * tr = NULL, *warning = NULL;
if (ctx) {
tr = _malloc(300);
if (!ctx->error) {
tr = _malloc(1000);
if (!ctx->error && d_get(ctx->responses[0], K_ERROR)) {
d_token_t* msg = d_get(ctx->responses[0], K_ERROR);
if (d_type(msg) == T_OBJECT) msg = d_get(msg, K_MESSAGE);
sprintf((warning = tr), "%s", msg ? d_string(msg) : "Error-Response!");
} else if (!ctx->error) {
b = d_get_intk(ctx->responses[0], K_RESULT);
if (block < b) block = b;

Expand Down
4 changes: 2 additions & 2 deletions c/src/core/client/client_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ static void init_mainnet(in3_chain_t* chain) {
}

static void init_btc(in3_chain_t* chain) {
initChain(chain, 0xFF01, "85613723dB1Bc29f332A37EeF10b61F8a4225c7e", "23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb", 1, 1, CHAIN_BTC, NULL);
initNode(chain, 0, "8f354b72856e516f1e931c97d1ed3bf1709f38c9", "http://localhost:8500");
initChain(chain, 0x99, "85613723dB1Bc29f332A37EeF10b61F8a4225c7e", "23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb", 1, 1, CHAIN_BTC, NULL);
initNode(chain, 0, "8f354b72856e516f1e931c97d1ed3bf1709f38c9", "https://in3.stage.slock.it/btc/nd-1");
if (chain->nodelist_upd8_params) {
_free(chain->nodelist_upd8_params);
chain->nodelist_upd8_params = NULL;
Expand Down
3 changes: 3 additions & 0 deletions c/src/core/client/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ static uint16_t update_waittime(uint64_t nodelist_block, uint64_t current_blk, u
static void check_autoupdate(const in3_ctx_t* ctx, in3_chain_t* chain, d_token_t* response_in3, node_match_t* node) {
if ((ctx->client->flags & FLAGS_AUTO_UPDATE_LIST) == 0) return;

// for now we do not support it yet
if (chain->chain_id == ETH_CHAIN_ID_BTC) return;

if (d_get_longk(response_in3, K_LAST_NODE_LIST) > d_get_longk(response_in3, K_CURRENT_BLOCK)) {
// this shouldn't be possible, so we ignore this lastNodeList and do NOT try to update the nodeList
return;
Expand Down
8 changes: 7 additions & 1 deletion c/src/verifier/btc/btc.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ in3_ret_t btc_verify_block(in3_vctx_t* vc, bytes32_t block_hash, bool json) {
if (json) {
d_token_t* tx = d_get(vc->result, key("tx")); // get transactions node
int tx_count = d_len(tx), i = 0; // and count its length
bytes32_t* tx_hashes = alloca(tx_count); // to reserve hashes-array
bytes32_t* tx_hashes = alloca(tx_count * sizeof(bytes32_t)); // to reserve hashes-array
for (d_iterator_t iter = d_iter(tx); iter.left; d_iter_next(&iter), i++) // iterate through all txs
hex_to_bytes(d_string(iter.token), 64, tx_hashes[i], 32); // and copy the hash into the array
btc_merkle_create_root(tx_hashes, tx_count, tmp); // calculate the merkle root
Expand Down Expand Up @@ -134,6 +134,12 @@ in3_ret_t in3_verify_btc(in3_vctx_t* vc) {
hex_to_bytes(d_string(block_hash), 64, hash, 32);
return btc_verify_block(vc, hash, d_len(params) > 1 ? d_get_int_at(params, 1) : 1);
}
if (strcmp(method, "getblockheader") == 0) {
d_token_t* block_hash = d_get_at(params, 0);
if (d_len(params) < 1 || d_type(params) != T_ARRAY || d_type(block_hash) != T_STRING || d_len(block_hash) != 64) return vc_err(vc, "Invalid params");
hex_to_bytes(d_string(block_hash), 64, hash, 32);
return btc_verify_block(vc, hash, d_len(params) > 1 ? d_get_int_at(params, 1) : 1);
}
return vc_err(vc, "Unsupported method");
}

Expand Down

0 comments on commit 99565a0

Please sign in to comment.