Skip to content

Commit 26423b2

Browse files
author
diogorac
committed
Jenkinsfile and astyle
1 parent 8afb601 commit 26423b2

File tree

5 files changed

+141
-143
lines changed

5 files changed

+141
-143
lines changed

Jenkinsfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
node('builder'){
2+
docker.image('riddleandcode/wallet-builder').inside('-u "root"') {
3+
checkout scm
4+
stage('Generating build') {
5+
sh 'mkdir -p build && cd build && cmake ../'
6+
}
7+
stage('Coding Guideline') {
8+
sh 'astyle "src/*.c" "inc/*.h" "tests/*.c" "tests/*.h" --style=google -s2'
9+
sh 'echo \'if [ $(find . -iname "*.orig" | wc -l) -eq 0 ]; then echo "According to guideline."; else echo "Not according to guideline" && exit 1; fi\' > guide && sh guide'
10+
}
11+
dir('build')
12+
{
13+
stage('Build') {
14+
sh 'make'
15+
}
16+
stage('Testing') {
17+
sh 'make check'
18+
sh 'xsltproc /opt/ctest/ctest2junix.xsl tests/Testing/$(head -1 tests/Testing/TAG)/Test.xml > CTestResults.xml '
19+
junit 'CTestResults.xml'
20+
cobertura coberturaReportFile: 'coverage.xml'
21+
}
22+
}
23+
}
24+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## c-bigchaindb
1+
## c-bigchaindb-tx
22

33
Transaction buider and signer.
44

inc/transaction.h

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,31 @@
99
#include "sha3.h"
1010
#include "ed25519-donna/ed25519.h"
1111

12-
typedef struct
13-
{
14-
char amount[8];
15-
// FIXED CONDITION FOR EDCURVE
16-
char details_public_key[45];
17-
char public_keys[8][45];
18-
uint8_t num_public_keys;
12+
typedef struct {
13+
char amount[8];
14+
// FIXED CONDITION FOR EDCURVE
15+
char details_public_key[45];
16+
char public_keys[8][45];
17+
uint8_t num_public_keys;
1918
} BIGCHAIN_OUTPUT;
2019

21-
typedef struct
22-
{
23-
char fulfillment[256];
24-
char fulfills[256];
25-
char owners_before[8][256];
26-
uint8_t num_owners;
20+
typedef struct {
21+
char fulfillment[256];
22+
char fulfills[256];
23+
char owners_before[8][256];
24+
uint8_t num_owners;
2725
} BIGCHAIN_INPUT;
2826

29-
typedef struct
30-
{
31-
char asset[256];
32-
char metadata[256];
33-
char operation[32];
34-
BIGCHAIN_OUTPUT outputs[8];
35-
uint8_t num_outputs;
36-
BIGCHAIN_INPUT inputs[8];
37-
uint8_t num_inputs;
38-
char version[8];
39-
char id[65];
27+
typedef struct {
28+
char asset[256];
29+
char metadata[256];
30+
char operation[32];
31+
BIGCHAIN_OUTPUT outputs[8];
32+
uint8_t num_outputs;
33+
BIGCHAIN_INPUT inputs[8];
34+
uint8_t num_inputs;
35+
char version[8];
36+
char id[65];
4037
} BIGCHAIN_TX;
4138

4239
void bigchain_sign_transaction(uint8_t *json_tx, uint16_t len, uint8_t *priv_key, uint8_t *pub_key, uint8_t *sig);

src/transaction.c

Lines changed: 81 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,118 +3,101 @@
33
/*
44
* Takes a json string, hashes it sha3_256 and signs it with ed25519.
55
*/
6-
void bigchain_sign_transaction(uint8_t *json_tx, uint16_t len, uint8_t *priv_key, uint8_t *pub_key, uint8_t *sig)
7-
{
8-
uint8_t hash[32] = {0};
9-
sha3_256((const unsigned char*)json_tx, len, hash);
10-
ed25519_sign(hash, 32, priv_key, pub_key, sig);
6+
void bigchain_sign_transaction(uint8_t *json_tx, uint16_t len, uint8_t *priv_key, uint8_t *pub_key, uint8_t *sig) {
7+
uint8_t hash[32] = {0};
8+
sha3_256((const unsigned char*)json_tx, len, hash);
9+
ed25519_sign(hash, 32, priv_key, pub_key, sig);
1110
}
1211

13-
char* bigchain_build_json_outputs(BIGCHAIN_OUTPUT *outputs, uint8_t num_outputs, char *json_obj)
14-
{
15-
char *p = json_obj;
16-
p = json_arrOpen( p, "outputs" );
17-
for(uint8_t i = 0; i < num_outputs; i++)
18-
{
19-
p = json_objOpen(p, NULL);
20-
p = json_str(p, "amount", outputs[i].amount);
21-
p = json_objOpen(p, "condition");
22-
23-
p = json_objOpen(p, "details");
24-
p = json_str(p, "public_key", outputs[i].details_public_key);
25-
p = json_str(p, "type", "ed25519-sha-256");
26-
p = json_objClose(p);
27-
28-
p = json_str(p, "uri", "ni:///sha-256;Vta3W592Kt_Y2ljfHEDZLd4OCZPHLiHyCgjNNKrrNwo?fpt=ed25519-sha-256&cost=131072");
29-
p = json_objClose(p);
30-
31-
p = json_arrOpen(p, "public_keys");
32-
for(uint8_t j = 0; j < outputs[i].num_public_keys; j++ )
33-
{
34-
p = json_str(p, NULL, outputs[i].public_keys[j]);
35-
}
36-
p = json_arrClose(p);
37-
38-
p = json_objClose(p);
39-
}
40-
p = json_arrClose(p);
41-
return p;
42-
}
12+
char* bigchain_build_json_outputs(BIGCHAIN_OUTPUT *outputs, uint8_t num_outputs, char *json_obj) {
13+
char *p = json_obj;
14+
p = json_arrOpen( p, "outputs" );
15+
for(uint8_t i = 0; i < num_outputs; i++) {
16+
p = json_objOpen(p, NULL);
17+
p = json_str(p, "amount", outputs[i].amount);
18+
p = json_objOpen(p, "condition");
19+
20+
p = json_objOpen(p, "details");
21+
p = json_str(p, "public_key", outputs[i].details_public_key);
22+
p = json_str(p, "type", "ed25519-sha-256");
23+
p = json_objClose(p);
4324

44-
char* bigchain_build_json_inputs(BIGCHAIN_INPUT *inputs, uint8_t num_inputs, char *json_obj)
45-
{
46-
char *p = json_obj;
47-
p = json_arrOpen( p, "inputs" );
48-
for(uint8_t i = 0; i < num_inputs; i++)
49-
{
50-
p = json_objOpen(p, NULL);
51-
if(inputs[i].fulfillment[0] != '\0')
52-
{
53-
p = json_str(p, "fulfillment", inputs[0].fulfillment);
54-
}
55-
else
56-
{
57-
p = json_null(p, "fulfillment");
58-
}
59-
60-
if(inputs[i].fulfills[0] != '\0')
61-
{
62-
p = json_str(p, "fulfills", inputs[0].fulfills);
63-
}
64-
else
65-
{
66-
p = json_null(p, "fulfills");
67-
}
68-
69-
p = json_arrOpen(p, "owners_before");
70-
for (uint8_t j = 0; j < inputs[0].num_owners; j++)
71-
{
72-
p = json_str(p, NULL, inputs[0].owners_before[j]);
73-
}
74-
p = json_arrClose(p);
75-
p = json_objClose(p);
25+
p = json_str(p, "uri", "ni:///sha-256;Vta3W592Kt_Y2ljfHEDZLd4OCZPHLiHyCgjNNKrrNwo?fpt=ed25519-sha-256&cost=131072");
26+
p = json_objClose(p);
27+
28+
p = json_arrOpen(p, "public_keys");
29+
for(uint8_t j = 0; j < outputs[i].num_public_keys; j++ ) {
30+
p = json_str(p, NULL, outputs[i].public_keys[j]);
7631
}
7732
p = json_arrClose(p);
78-
return p;
79-
}
8033

81-
void bigchain_build_json_tx(BIGCHAIN_TX *tx, char *json_tx)
82-
{
83-
char *p = json_tx;
84-
p = json_objOpen(p, NULL);
85-
86-
// ASSET
87-
p = json_objOpen(p, "asset");
88-
p = atoa(p, tx->asset);
8934
p = json_objClose(p);
35+
}
36+
p = json_arrClose(p);
37+
return p;
38+
}
9039

91-
// ID
92-
if(tx->id[0] != '\0')
93-
{
94-
p = json_str(p, "id", tx->id);
40+
char* bigchain_build_json_inputs(BIGCHAIN_INPUT *inputs, uint8_t num_inputs, char *json_obj) {
41+
char *p = json_obj;
42+
p = json_arrOpen( p, "inputs" );
43+
for(uint8_t i = 0; i < num_inputs; i++) {
44+
p = json_objOpen(p, NULL);
45+
if(inputs[i].fulfillment[0] != '\0') {
46+
p = json_str(p, "fulfillment", inputs[0].fulfillment);
47+
} else {
48+
p = json_null(p, "fulfillment");
9549
}
96-
else
97-
{
98-
p = json_null(p, "id");
50+
51+
if(inputs[i].fulfills[0] != '\0') {
52+
p = json_str(p, "fulfills", inputs[0].fulfills);
53+
} else {
54+
p = json_null(p, "fulfills");
9955
}
10056

101-
// INPUTS
102-
p = bigchain_build_json_inputs(tx->inputs, tx->num_inputs, p);
103-
104-
// METADA
105-
p = json_objOpen(p, "metadata");
106-
p = atoa(p, tx->metadata);
57+
p = json_arrOpen(p, "owners_before");
58+
for (uint8_t j = 0; j < inputs[0].num_owners; j++) {
59+
p = json_str(p, NULL, inputs[0].owners_before[j]);
60+
}
61+
p = json_arrClose(p);
10762
p = json_objClose(p);
63+
}
64+
p = json_arrClose(p);
65+
return p;
66+
}
10867

109-
// OPERATION
110-
p = json_str(p, "operation", tx->operation);
68+
void bigchain_build_json_tx(BIGCHAIN_TX *tx, char *json_tx) {
69+
char *p = json_tx;
70+
p = json_objOpen(p, NULL);
11171

112-
// OUTPUTS
113-
p = bigchain_build_json_outputs(tx->outputs, tx->num_outputs, p);
72+
// ASSET
73+
p = json_objOpen(p, "asset");
74+
p = atoa(p, tx->asset);
75+
p = json_objClose(p);
76+
77+
// ID
78+
if(tx->id[0] != '\0') {
79+
p = json_str(p, "id", tx->id);
80+
} else {
81+
p = json_null(p, "id");
82+
}
83+
84+
// INPUTS
85+
p = bigchain_build_json_inputs(tx->inputs, tx->num_inputs, p);
86+
87+
// METADA
88+
p = json_objOpen(p, "metadata");
89+
p = atoa(p, tx->metadata);
90+
p = json_objClose(p);
91+
92+
// OPERATION
93+
p = json_str(p, "operation", tx->operation);
94+
95+
// OUTPUTS
96+
p = bigchain_build_json_outputs(tx->outputs, tx->num_outputs, p);
97+
98+
// VERSION
99+
p = json_str(p, "version", tx->version);
100+
p = json_objClose(p);
114101

115-
// VERSION
116-
p = json_str(p, "version", tx->version);
117-
p = json_objClose(p);
118-
119102
}
120103

tests/test_sig.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,20 @@
1212
#define TEST_DETAILS_PUBLIC_KEY "6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a"
1313
#define TEST_PUBLIC_KEY_0 "6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a"
1414
static const char* tx_json =
15-
"{\"asset\":{\"data\":{\"bicycle\":{\"manufacturer\":\"bkfab\",\"serial_number\":\"abcd1234\"}}},\"id\":null,\"inputs\":[{\"fulfillment\":null,\"fulfills\":null,\"owners_before\":[\"6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a\"]}],\"metadata\":{\"planet\":\"earth\"},\"operation\":\"CREATE\",\"outputs\":[{\"amount\":\"1\",\"condition\":{\"details\":{\"public_key\":\"6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a\",\"type\":\"ed25519-sha-256\"},\"uri\":\"ni:///sha-256;Vta3W592Kt_Y2ljfHEDZLd4OCZPHLiHyCgjNNKrrNwo?fpt=ed25519-sha-256&cost=131072\"},\"public_keys\":[\"6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a\"]}],\"version\":\"2.0\"}";
15+
"{\"asset\":{\"data\":{\"bicycle\":{\"manufacturer\":\"bkfab\",\"serial_number\":\"abcd1234\"}}},\"id\":null,\"inputs\":[{\"fulfillment\":null,\"fulfills\":null,\"owners_before\":[\"6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a\"]}],\"metadata\":{\"planet\":\"earth\"},\"operation\":\"CREATE\",\"outputs\":[{\"amount\":\"1\",\"condition\":{\"details\":{\"public_key\":\"6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a\",\"type\":\"ed25519-sha-256\"},\"uri\":\"ni:///sha-256;Vta3W592Kt_Y2ljfHEDZLd4OCZPHLiHyCgjNNKrrNwo?fpt=ed25519-sha-256&cost=131072\"},\"public_keys\":[\"6k17YAe4mJsqwPNgGj9tE1aMYLhpeqgJJivqaHeTTU5a\"]}],\"version\":\"2.0\"}";
1616
char privkey[] = {'\x24','\x70','\x31','\x98','\x89','\xfe','\xd2','\x13','\x9a','\x6d','\xd9','\x9e','\xa3','\xae','\xf2','\xd3','\x96','\xe9','\xe7','\x47','\x51','\x32','\x33','\x7b','\xdb','\x04','\xd4','\x7c','\xa7','\xd2','\x02','\x8c'};
1717
char pubkey[] = {'\x55','\x4e','\x89','\x70','\x1b','\x6d','\xca','\x9b','\x28','\x61','\x1f','\xb3','\x61','\x41','\x71','\x3a','\x2e','\x18','\x52','\x02','\x0e','\x8e','\xa8','\xa0','\x2e','\x27','\xda','\x40','\xef','\xac','\xcc','\x25'};
1818

19-
void prepare_inputs(BIGCHAIN_INPUT *inputs, uint8_t *num_inputs)
20-
{
19+
void prepare_inputs(BIGCHAIN_INPUT *inputs, uint8_t *num_inputs) {
2120
memset(inputs, 0, sizeof(BIGCHAIN_INPUT));
22-
21+
2322
// Fill input struct
2423
memcpy(inputs[0].owners_before[0], TEST_OWNER_BEFORE, strlen(TEST_OWNER_BEFORE));
2524
inputs[0].num_owners = 1;
2625
*num_inputs = 1;
2726
}
2827

29-
void prepare_outputs(BIGCHAIN_OUTPUT *outputs, uint8_t *num_outputs)
30-
{
28+
void prepare_outputs(BIGCHAIN_OUTPUT *outputs, uint8_t *num_outputs) {
3129
memset(outputs, 0, sizeof(BIGCHAIN_OUTPUT));
3230

3331
// Fill output struct
@@ -38,11 +36,10 @@ void prepare_outputs(BIGCHAIN_OUTPUT *outputs, uint8_t *num_outputs)
3836
*num_outputs = 1;
3937
}
4038

41-
void prepare_tx(BIGCHAIN_TX *tx)
42-
{
39+
void prepare_tx(BIGCHAIN_TX *tx) {
4340
prepare_inputs(tx->inputs, &(tx->num_inputs));
4441
prepare_outputs(tx->outputs, &(tx->num_outputs));
45-
42+
4643
memcpy(tx->asset, TEST_ASSET, strlen(TEST_ASSET));
4744
memcpy(tx->metadata, TEST_METADATA, strlen(TEST_METADATA));
4845
memcpy(tx->operation, TEST_OPERATION, strlen(TEST_OPERATION));
@@ -52,11 +49,11 @@ void prepare_tx(BIGCHAIN_TX *tx)
5249
void test_sig(void) {
5350
uint8_t hash[32] = {0}, sig[640] = {0};
5451

55-
// Hashing 256
52+
// Hashing 256
5653
sha3_256((const unsigned char*)tx_json, strlen(tx_json), hash);
57-
uint8_t cmp_hash[] ={'\xbb','\xb7','\xdf','\xd5','\x1b','\xe3','\xbb','\x66','\x91','\x80','\xf4','\x8b','\x37','\xf1','\x86','\x98','\xb8','\x2c','\xfc','\x40','\xea','\x4c','\xa4','\x95','\x2a','\x1c','\x82','\xeb','\x11','\xff','\x5f','\xb5'};
54+
uint8_t cmp_hash[] = {'\xbb','\xb7','\xdf','\xd5','\x1b','\xe3','\xbb','\x66','\x91','\x80','\xf4','\x8b','\x37','\xf1','\x86','\x98','\xb8','\x2c','\xfc','\x40','\xea','\x4c','\xa4','\x95','\x2a','\x1c','\x82','\xeb','\x11','\xff','\x5f','\xb5'};
5855
TEST_ASSERT_EQUAL(0, memcmp(cmp_hash, hash, 32));
59-
56+
6057
// ED25519 signing
6158
uint8_t cmp_sig[] = {'\x8d','\x31','\xa2','\x89','\xe9','\xa5','\x74','\xdd','\xa7','\x0d','\x06','\xa7','\x18','\x09','\xf7','\xc4','\x58','\x07','\x0d','\x41','\xd8','\x71','\x4b','\x5a','\x3b','\x6d','\xe6','\xfa','\x22','\xca','\x71','\x7e','\xdd','\x18','\x9a','\x0b','\xf6','\xfa','\x85','\x25','\x38','\x50','\x1e','\x4f','\xa2','\x9e','\x3f','\xae','\x70','\x2e','\xcf','\xd2','\x39','\x22','\xab','\x2d','\x16','\x80','\x20','\x0f','\xd4','\xef','\x99','\x02'};
6259
ed25519_sign(hash, 32, (const unsigned char*) privkey, (const unsigned char*) pubkey, sig);
@@ -66,9 +63,8 @@ void test_sig(void) {
6663
TEST_ASSERT_EQUAL(0, memcmp(cmp_sig, sig, 64));
6764
}
6865

69-
void test_bigchain_build_json_outputs(void)
70-
{
71-
BIGCHAIN_OUTPUT outputs[1];
66+
void test_bigchain_build_json_outputs(void) {
67+
BIGCHAIN_OUTPUT outputs[1];
7268
char outputs_json[512] = {0};
7369
uint8_t num = 0;
7470
prepare_outputs(outputs, &num );
@@ -79,22 +75,20 @@ void test_bigchain_build_json_outputs(void)
7975

8076
}
8177

82-
void test_bigchain_build_json_inputs(void)
83-
{
78+
void test_bigchain_build_json_inputs(void) {
8479
BIGCHAIN_INPUT inputs[1];
8580
char inputs_json[256] = {0};
8681
uint8_t num = 0;
8782

8883
prepare_inputs(inputs, &num);
89-
84+
9085
// Builds input json from structure
9186
bigchain_build_json_inputs(inputs, 1, inputs_json);
9287
TEST_ASSERT_EQUAL(0, memcmp(TEST_INPUTS, inputs_json, strlen(TEST_INPUTS)));
9388

9489
}
9590

96-
void test_bigchain_build_json_tx(void)
97-
{
91+
void test_bigchain_build_json_tx(void) {
9892
BIGCHAIN_TX tx;
9993
char json[6000] = {0};
10094

0 commit comments

Comments
 (0)