Skip to content

Commit 2774b9a

Browse files
Merge branch 'develop' into 'master'
Develop See merge request in3/c/in3-core!240
2 parents 50c67e9 + 7c355f3 commit 2774b9a

File tree

8 files changed

+158
-116
lines changed

8 files changed

+158
-116
lines changed

Diff for: c/docs/1_install.md

+14
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ Default-Value: `-DEVM_GAS=ON`
112112
Default-Value: `-DFAST_MATH=OFF`
113113

114114

115+
#### GCC_ANALYZER
116+
117+
GCC10 static code analyses
118+
119+
Default-Value: `-DGCC_ANALYZER=OFF`
120+
121+
115122
#### IN3API
116123

117124
build the USN-API which offer better interfaces and additional functions on top of the pure verification
@@ -154,6 +161,13 @@ Default-Value: `-DIPFS=ON`
154161
Default-Value: `-DJAVA=OFF`
155162

156163

164+
#### LEDGER_NANO
165+
166+
include support for nano ledger
167+
168+
Default-Value: `-DLEDGER_NANO=OFF`
169+
170+
157171
#### PAY_ETH
158172

159173
support for direct Eth-Payment

Diff for: c/docs/2_examples.md

+58
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,64 @@ int main() {
599599

600600
```
601601
602+
### ledger_sign
603+
604+
source : [in3-c/c/examples/ledger_sign.c](https://github.com/slockit/in3-c/blob/master/c/examples/ledger_sign.c)
605+
606+
607+
608+
```c
609+
610+
#include <in3/client.h> // the core client
611+
#include <in3/eth_api.h> // functions for direct api-access
612+
#include <in3/in3_init.h> // if included the verifier will automaticly be initialized.
613+
#include <in3/ledger_signer.h> //to invoke ledger nano device for signing
614+
#include <in3/log.h> // logging functions
615+
#include <in3/utils.h>
616+
#include <stdio.h>
617+
618+
static void send_tx_api(in3_t* in3);
619+
620+
int main() {
621+
// create new incubed client
622+
uint8_t bip_path[5] = {44, 60, 0, 0, 0};
623+
in3_t* in3 = in3_for_chain(ETH_CHAIN_ID_MAINNET);
624+
in3_log_set_level(LOG_DEBUG);
625+
// setting ledger nano s to be the default signer for incubed client
626+
// it will cause the transaction or any msg to be sent to ledger nanos device for siging
627+
eth_ledger_set_signer(in3, bip_path);
628+
629+
// send tx using API
630+
send_tx_api(in3);
631+
632+
// cleanup client after usage
633+
in3_free(in3);
634+
}
635+
636+
void send_tx_api(in3_t* in3) {
637+
// prepare parameters
638+
address_t to, from;
639+
hex_to_bytes("0xC51fBbe0a68a7cA8d33f14a660126Da2A2FAF8bf", -1, from, 20);
640+
hex_to_bytes("0xd46e8dd67c5d32be8058bb8eb970870f07244567", -1, to, 20);
641+
642+
bytes_t* data = hex_to_new_bytes("d46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675", 82);
643+
644+
// send the tx
645+
bytes_t* tx_hash = eth_sendTransaction(in3, from, to, OPTIONAL_T_VALUE(uint64_t, 0x96c0), OPTIONAL_T_VALUE(uint64_t, 0x9184e72a000), OPTIONAL_T_VALUE(uint256_t, to_uint256(0x9184e72a)), OPTIONAL_T_VALUE(bytes_t, *data), OPTIONAL_T_UNDEFINED(uint64_t));
646+
647+
// if the result is null there was an error and we can get the latest error message from eth_last_error()
648+
if (!tx_hash)
649+
printf("error sending the tx : %s\n", eth_last_error());
650+
else {
651+
printf("Transaction hash: ");
652+
b_print(tx_hash);
653+
b_free(tx_hash);
654+
}
655+
b_free(data);
656+
}
657+
658+
```
659+
602660
### send_transaction
603661

604662
source : [in3-c/c/examples/send_transaction.c](https://github.com/slockit/in3-c/blob/master/c/examples/send_transaction.c)

Diff for: c/examples/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
- [ipfs_put_get](./ipfs_put_get.c)
2323
using the IPFS module
2424

25+
- [ledger_sign](./ledger_sign.c)
26+
2527
- [send_transaction](./send_transaction.c)
2628
sending a transaction including signing it with a private key
2729

Diff for: c/include/in3/data.h

+18-15
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,22 @@ typedef struct json_parser {
104104
* Objects or arrays will return 0x.
105105
*/
106106
bytes_t d_to_bytes(d_token_t* item);
107-
int d_bytes_to(d_token_t* item, uint8_t* dst, const int max); /**< writes the byte-representation to the dst. details see d_to_bytes.*/
108-
bytes_t* d_bytes(const d_token_t* item); /**< returns the value as bytes (Carefully, make sure that the token is a bytes-type!)*/
109-
bytes_t* d_bytesl(d_token_t* item, size_t l); /**< returns the value as bytes with length l (may reallocates) */
110-
char* d_string(const d_token_t* item); /**< converts the value as string. Make sure the type is string! */
111-
int32_t d_int(const d_token_t* item); /**< returns the value as integer. only if type is integer */
112-
int32_t d_intd(const d_token_t* item, const uint32_t def_val); /**< returns the value as integer or if NULL the default. only if type is integer */
113-
uint64_t d_long(const d_token_t* item); /**< returns the value as long. only if type is integer or bytes, but short enough */
114-
uint64_t d_longd(const d_token_t* item, const uint64_t def_val); /**< returns the value as long or if NULL the default. only if type is integer or bytes, but short enough */
115-
bytes_t** d_create_bytes_vec(const d_token_t* arr); /** creates a array of bytes from JOSN-array */
116-
static inline d_type_t d_type(const d_token_t* item) { return item == NULL ? T_NULL : (item->len & 0xF0000000) >> 28; } /**< type of the token */
117-
static inline int d_len(const d_token_t* item) { return item == NULL ? 0 : item->len & 0xFFFFFFF; } /**< number of elements in the token (only for object or array, other will return 0) */
118-
bool d_eq(const d_token_t* a, const d_token_t* b); /**< compares 2 token and if the value is equal */
119-
d_key_t keyn(const char* c, const size_t len); /**< generates the keyhash for the given stringrange as defined by len */
107+
int d_bytes_to(d_token_t* item, uint8_t* dst, const int max); /**< writes the byte-representation to the dst. details see d_to_bytes.*/
108+
bytes_t* d_bytes(const d_token_t* item); /**< returns the value as bytes (Carefully, make sure that the token is a bytes-type!)*/
109+
bytes_t* d_bytesl(d_token_t* item, size_t l); /**< returns the value as bytes with length l (may reallocates) */
110+
char* d_string(const d_token_t* item); /**< converts the value as string. Make sure the type is string! */
111+
int32_t d_int(const d_token_t* item); /**< returns the value as integer. only if type is integer */
112+
int32_t d_intd(const d_token_t* item, const uint32_t def_val); /**< returns the value as integer or if NULL the default. only if type is integer */
113+
uint64_t d_long(const d_token_t* item); /**< returns the value as long. only if type is integer or bytes, but short enough */
114+
uint64_t d_longd(const d_token_t* item, const uint64_t def_val); /**< returns the value as long or if NULL the default. only if type is integer or bytes, but short enough */
115+
bytes_t** d_create_bytes_vec(const d_token_t* arr); /** creates a array of bytes from JOSN-array */
116+
static inline d_type_t d_type(const d_token_t* item) { return (item ? ((item->len & 0xF0000000) >> 28) : T_NULL); } /**< type of the token */
117+
static inline int d_len(const d_token_t* item) { /**< number of elements in the token (only for object or array, other will return 0) */
118+
if (item == NULL) return 0;
119+
return item->len & 0xFFFFFFF;
120+
}
121+
bool d_eq(const d_token_t* a, const d_token_t* b); /**< compares 2 token and if the value is equal */
122+
d_key_t keyn(const char* c, const size_t len); /**< generates the keyhash for the given stringrange as defined by len */
120123

121124
d_token_t* d_get(d_token_t* item, const uint16_t key); /**< returns the token with the given propertyname (only if item is a object) */
122125
d_token_t* d_get_or(d_token_t* item, const uint16_t key1, const uint16_t key2); /**< returns the token with the given propertyname or if not found, tries the other. (only if item is a object) */
@@ -191,8 +194,8 @@ typedef struct d_iterator {
191194
int left; /**< number of result left */
192195
} d_iterator_t;
193196

194-
static inline d_iterator_t d_iter(d_token_t* parent) { return (d_iterator_t){.left = d_len(parent), .token = parent + 1}; } /**< creates a iterator for a object or array */
195-
static inline bool d_iter_next(d_iterator_t* const iter) {
197+
d_iterator_t d_iter(d_token_t* parent); /**< creates a iterator for a object or array */
198+
static inline bool d_iter_next(d_iterator_t* const iter) {
196199
iter->token = d_next(iter->token);
197200
return iter->left--;
198201
} /**< fetched the next token an returns a boolean indicating whther there is a next or not.*/

Diff for: c/include/in3/ledger_signer.h

+2
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,7 @@
4545
#include "client.h"
4646

4747
in3_ret_t eth_ledger_set_signer(in3_t* in3, uint8_t* bip_path);
48+
in3_ret_t eth_ledger_get_public_key(uint8_t* i_bip_path, uint8_t* o_public_key);
49+
in3_ret_t eth_ledger_sign(void* ctx, d_signature_type_t type, bytes_t message, bytes_t account, uint8_t* dst);
4850

4951
#endif

0 commit comments

Comments
 (0)