1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

Merge pull request #224 from saleemrashid/nem-mosaics-build-time

Generate nem_mosaics.[ch] at build time
This commit is contained in:
Pavol Rusnak 2017-10-09 21:16:00 +02:00 committed by GitHub
commit 08e0a31b62
8 changed files with 32 additions and 133 deletions

View File

@ -8,26 +8,29 @@ addons:
- build-essential - build-essential
- gcc-arm-none-eabi - gcc-arm-none-eabi
- libnewlib-arm-none-eabi - libnewlib-arm-none-eabi
- protobuf-compiler
- libprotobuf-dev
- python-protobuf
env: env:
global: global:
- MAKEFLAGS=-j2 - MAKEFLAGS=-j2
- PROTOBUF_VERSION=3.4.0
matrix: matrix:
- DEBUG_LINK=0 FASTFLASH=0 - DEBUG_LINK=0 FASTFLASH=0
- DEBUG_LINK=1 FASTFLASH=0 - DEBUG_LINK=1 FASTFLASH=0
- DEBUG_LINK=0 FASTFLASH=1 - DEBUG_LINK=0 FASTFLASH=1
- DEBUG_LINK=1 FASTFLASH=1 - DEBUG_LINK=1 FASTFLASH=1
install:
- curl -LO "https://github.com/google/protobuf/releases/download/v${PROTOBUF_VERSION}/protoc-${PROTOBUF_VERSION}-linux-x86_64.zip"
- unzip "protoc-${PROTOBUF_VERSION}-linux-x86_64.zip" -d protoc
- export PATH="$(pwd)/protoc/bin:$PATH"
- pip2 install --user "protobuf==${PROTOBUF_VERSION}"
script: script:
- make -C vendor/libopencm3 lib/stm32/f2 - make -C vendor/libopencm3 lib/stm32/f2
- make -C vendor/nanopb/generator/proto - make -C vendor/nanopb/generator/proto
- make - make
- make -C bootloader - make -C bootloader
- make -C fastflash - make -C fastflash
- sed -i '/, deprecated = true/d' firmware/protob/messages.proto # protobuf 2.5 compatibility :-/
- make -C firmware/protob - make -C firmware/protob
- make -C firmware - make -C firmware
- make -C demo - make -C demo

2
firmware/.gitignore vendored
View File

@ -1,2 +1,4 @@
coins_array.h coins_array.h
coins_count.h coins_count.h
nem_mosaics.[ch]

View File

@ -105,6 +105,8 @@ bootloader.o: ../fastflash/bootloader.bin
coins.c crypto.c fsm.c transaction.c: coins_count.h coins.c crypto.c fsm.c transaction.c: coins_count.h
coins.c: coins_array.h coins.c: coins_array.h
nem2.c layout2.c: nem_mosaics.h
################# #################
# Code Generation # Code Generation
coins_count.h: coins-gen.py coins.json coins_count.h: coins-gen.py coins.json
@ -113,5 +115,9 @@ coins_count.h: coins-gen.py coins.json
coins_array.h: coins-gen.py coins.json coins_array.h: coins-gen.py coins.json
./$< array > $@ ./$< array > $@
nem_mosaics.c nem_mosaics.h: nem_mosaics.py nem_mosaics.json
./$<
clean:: clean::
rm -f coins_count.h coins_array.h rm -f coins_count.h coins_array.h
rm -f nem_mosaics.c nem_mosaics.h

View File

@ -1,7 +1,7 @@
/* /*
* This file is part of the TREZOR project. * This file is part of the TREZOR project.
* *
* Copyright (C) 2017 Saleem Rashid <dev@saleemrashid.com> * Copyright (C) 2017 Saleem Rashid <trezor@saleemrashid.com>
* *
* This library is free software: you can redistribute it and/or modify * This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by

View File

@ -1,7 +1,7 @@
/* /*
* This file is part of the TREZOR project. * This file is part of the TREZOR project.
* *
* Copyright (C) 2017 Saleem Rashid <dev@saleemrashid.com> * Copyright (C) 2017 Saleem Rashid <trezor@saleemrashid.com>
* *
* This library is free software: you can redistribute it and/or modify * This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by

View File

@ -1,104 +0,0 @@
// This file is automatically generated by nem_mosaics.py -- DO NOT EDIT!
#include "nem_mosaics.h"
const NEMMosaicDefinition NEM_MOSAIC_DEFINITIONS[NEM_MOSAIC_DEFINITIONS_COUNT] = {{
.has_name = true,
.name = "XEM",
.has_ticker = true,
.ticker = " XEM",
.has_namespace = true,
.namespace = "nem",
.has_mosaic = true,
.mosaic = "xem",
.has_divisibility = true,
.divisibility = 6,
},
{
.has_name = true,
.name = "DIMCOIN",
.has_ticker = true,
.ticker = " DIM",
.has_namespace = true,
.namespace = "dim",
.has_mosaic = true,
.mosaic = "coin",
.has_divisibility = true,
.divisibility = 6,
.has_levy = true,
.levy = NEMMosaicLevy_MosaicLevy_Percentile,
.has_fee = true,
.fee = 10,
.has_levy_namespace = true,
.levy_namespace = "dim",
.has_levy_mosaic = true,
.levy_mosaic = "coin",
.networks_count = 1,
.networks = { 104 },
},
{
.has_name = true,
.name = "DIM TOKEN",
.has_ticker = true,
.ticker = " DIMTOK",
.has_namespace = true,
.namespace = "dim",
.has_mosaic = true,
.mosaic = "token",
.has_divisibility = true,
.divisibility = 6,
.networks_count = 1,
.networks = { 104 },
},
{
.has_name = true,
.name = "Breeze Token",
.has_ticker = true,
.ticker = " BREEZE",
.has_namespace = true,
.namespace = "breeze",
.has_mosaic = true,
.mosaic = "breeze-token",
.has_divisibility = true,
.divisibility = 0,
.networks_count = 1,
.networks = { 104 },
},
{
.has_name = true,
.name = "PacNEM Game Credits",
.has_ticker = true,
.ticker = " PAC:HRT",
.has_namespace = true,
.namespace = "pacnem",
.has_mosaic = true,
.mosaic = "heart",
.has_divisibility = true,
.divisibility = 0,
.networks_count = 1,
.networks = { 104 },
},
{
.has_name = true,
.name = "PacNEM Score Tokens",
.has_ticker = true,
.ticker = " PAC:CHS",
.has_namespace = true,
.namespace = "pacnem",
.has_mosaic = true,
.mosaic = "cheese",
.has_divisibility = true,
.divisibility = 6,
.has_levy = true,
.levy = NEMMosaicLevy_MosaicLevy_Percentile,
.has_fee = true,
.fee = 100,
.has_levy_namespace = true,
.levy_namespace = "nem",
.has_levy_mosaic = true,
.levy_mosaic = "xem",
.networks_count = 1,
.networks = { 104 },
}};
const NEMMosaicDefinition *NEM_MOSAIC_DEFINITION_XEM = NEM_MOSAIC_DEFINITIONS;

View File

@ -1,13 +0,0 @@
// This file is automatically generated by nem_mosaics.py -- DO NOT EDIT!
#ifndef __NEM_MOSAICS_H__
#define __NEM_MOSAICS_H__
#include "types.pb.h"
#define NEM_MOSAIC_DEFINITIONS_COUNT (6)
extern const NEMMosaicDefinition NEM_MOSAIC_DEFINITIONS[NEM_MOSAIC_DEFINITIONS_COUNT];
extern const NEMMosaicDefinition *NEM_MOSAIC_DEFINITION_XEM;
#endif

View File

@ -1,8 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python2
import json, os import json, os, sys
import collections, numbers
from google.protobuf import json_format from google.protobuf import json_format
from itertools import chain from itertools import chain
import protob.types_pb2 as types
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "protob"))
import types_pb2 as types
HEADER_TEMPLATE = """ HEADER_TEMPLATE = """
// This file is automatically generated by nem_mosaics.py -- DO NOT EDIT! // This file is automatically generated by nem_mosaics.py -- DO NOT EDIT!
@ -31,13 +36,13 @@ const NEMMosaicDefinition *NEM_MOSAIC_DEFINITION_XEM = NEM_MOSAIC_DEFINITIONS;
""".lstrip() """.lstrip()
def format_primitive(value): def format_primitive(value):
if type(value) is bool: if isinstance(value, bool):
return ("false", "true")[value] return ("false", "true")[value]
elif type(value) in (int, float): elif isinstance(value, numbers.Number):
return str(value) return str(value)
elif type(value) is str: elif isinstance(value, basestring):
return json.dumps(value) return json.dumps(value)
elif type(value) is list: elif isinstance(value, collections.Sequence):
return "{ " + ", ".join( return "{ " + ", ".join(
format_primitive(item) for item in value format_primitive(item) for item in value
) + " }" ) + " }"
@ -61,14 +66,14 @@ def format_field(field, value):
return format_primitive(value) return format_primitive(value)
def field_to_meta(field, value): def field_to_meta(field, value):
if hasattr(value, "_values"): if field.label == field.LABEL_REPEATED:
return ("{}_count".format(field.name), format_primitive(len(value._values))) return ("{}_count".format(field.name), format_primitive(len(value)))
else: else:
return ("has_{}".format(field.name), format_primitive(True)) return ("has_{}".format(field.name), format_primitive(True))
def message_to_struct(_message, proto): def message_to_struct(_message, proto):
message = json_format.ParseDict(_message, proto()) message = json_format.ParseDict(_message, proto())
return dict(chain.from_iterable( return collections.OrderedDict(chain.from_iterable(
( (
field_to_meta(field, value), field_to_meta(field, value),
(field.name, format_field(field, value)), (field.name, format_field(field, value)),