Skip to content

Commit

Permalink
Merge pull request #57 from obsidiansystems/erc20interactions
Browse files Browse the repository at this point in the history
ERC20 support
  • Loading branch information
alexfmpe authored Apr 20, 2021
2 parents 98818ef + 2445562 commit 2694cd1
Show file tree
Hide file tree
Showing 18 changed files with 727 additions and 600 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2

VERSION_TAG ?= $(shell echo "$(GIT_DESCRIBE)" | cut -f1 -d-)
APPVERSION_M=0
APPVERSION_N=4
APPVERSION_P=3
APPVERSION_N=5
APPVERSION_P=0
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

# Only warn about version tags if specified/inferred
Expand Down
11 changes: 5 additions & 6 deletions nix/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ target=
usage() {
echo "usage: ./install.sh [build-type arg] [options]"
echo "build-type:"
echo " -t : Target to build from source. Takes either 's' or 't' as an arg"
echo " -t : Target to build from source. Takes either 's' or 'x' as an arg"
echo " -x : Hex file. Takes either a tar.gz or directory containing the app.hex and app.manifest files"
echo "options:"
echo " -n : Skip tests. Has no effect when run with -x build arg"
exit 0

}

build() {
Expand All @@ -29,7 +29,7 @@ build() {
install() {
if [[ $target == "" ]]
then usage
else
else
local release_file
release_file=$(build -A "nano.${target}.release.app" "$@")
bash "$root/nix/app-installer-impl.sh" "$release_file"
Expand All @@ -38,7 +38,7 @@ install() {

while getopts ":h:t:x:n" opt; do
case ${opt} in
t )
t )
## Required target arg: Specify x or s
if [[ "$OPTARG" == "s" || "$OPTARG" == "x" ]]
then
Expand All @@ -60,7 +60,7 @@ while getopts ":h:t:x:n" opt; do
h ) usage
;;
\? ) usage

;;
esac
done
Expand All @@ -83,4 +83,3 @@ else
## INSTALL FROM SOURCE
install "$@"
fi

119 changes: 119 additions & 0 deletions src/evm_abi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
static void output_evm_amount_to_string(char *const out, size_t const out_size, output_prompt_t const *const in);
static void output_evm_address_to_string(char *const out, size_t const out_size, output_prompt_t const *const in);
static void output_evm_bytes32_to_string(char *const out, size_t const out_size, output_prompt_t const *const in);
static void setup_prompt_evm_address(uint8_t *buffer, output_prompt_t *const prompt);
static void setup_prompt_evm_amount(uint8_t *buffer, output_prompt_t *const prompt);
static void setup_prompt_evm_bytes32(uint8_t *buffer, output_prompt_t *const prompt);

#define ABI_ADDRESS(name) \
ABI_PARAMETER(name, setup_prompt_evm_address, output_evm_address_to_string)

#define ABI_AMOUNT(name) \
ABI_PARAMETER(name, setup_prompt_evm_amount, output_evm_amount_to_string)

#define ABI_BYTES32(name) \
ABI_PARAMETER(name, setup_prompt_evm_bytes32, output_evm_bytes32_to_string)

#define ERC20_ABI \
ABI_METHOD("\x84\x56\xcb\x59", 0, \
"pause", \
) \
ABI_METHOD("\x3f\x4b\xa8\x3a", 0, \
"unpause", \
) \
ABI_METHOD("\x42\x96\x6c\x68", 1, \
"burn", \
ABI_AMOUNT("amount")) \
ABI_METHOD("\x40\xc1\x0f\x19", 2, \
"mint", \
ABI_ADDRESS("to") \
ABI_AMOUNT("amount") \
) \
ABI_METHOD("\xa9\x05\x9c\xbb", 2, \
"transfer", \
ABI_ADDRESS("recipient") \
ABI_AMOUNT("amount")) \
ABI_METHOD("\x79\xcc\x67\x90", 2, \
"burnFrom", \
ABI_ADDRESS("account") \
ABI_AMOUNT("amount")) \
ABI_METHOD("\x09\x5e\xa7\xb3", 2, \
"approve", \
ABI_ADDRESS("spender") \
ABI_AMOUNT("amount")) \
ABI_METHOD("\x39\x50\x93\x51", 2, \
"increaseAllowance", \
ABI_ADDRESS("spender") \
ABI_AMOUNT("addedValue")) \
ABI_METHOD("\xa4\x57\xc2\xd7", 2, \
"decreaseAllowance", \
ABI_ADDRESS("spender") \
ABI_AMOUNT("subtractedValue")) \
ABI_METHOD("\x23\xb8\x72\xdd", 3, \
"transferFrom", \
ABI_ADDRESS("sender") \
ABI_ADDRESS("recipient") \
ABI_AMOUNT("amount")) \
ABI_METHOD("\x2f\x2f\xf1\x5d", 2, \
"grantRole", \
ABI_BYTES32("role") \
ABI_ADDRESS("account")) \
ABI_METHOD("\x36\x56\x8a\xbe", 2, \
"renounceRole", \
ABI_BYTES32("role") \
ABI_ADDRESS("account")) \
ABI_METHOD("\xd5\x47\x74\x1f", 2, \
"revokeRole", \
ABI_BYTES32("role") \
ABI_ADDRESS("account")) \


struct contract_endpoint_param {
char *name;
void (*setup_prompt)(uint8_t *buffer, output_prompt_t *const prompt);
void (*output_prompt)(char *const out, size_t const out_size, output_prompt_t const *const in);
};

#define ABI_MAX_PARAMETERS 3

struct contract_endpoint {
char *method_name;
uint8_t selector[4];
uint8_t parameters_count;
struct contract_endpoint_param parameters[ABI_MAX_PARAMETERS];
};

static const struct contract_endpoint known_endpoints[] = {
#define ABI_PARAMETER(name_, setup_prompt_, output_prompt_) \
{ .name = name_, \
.setup_prompt = setup_prompt_, \
.output_prompt = output_prompt_, \
},

#define ABI_METHOD(selector_, parameters_count_, name_, parameters_...) \
{ .method_name = name_, \
.selector = selector_, \
.parameters_count = parameters_count_, \
.parameters = {parameters_}, \
},

ERC20_ABI
#undef ABI_METHOD
#undef ABI_PARAMETER
};

#define ABI_PARAMETER(name_, setup_prompt_, output_prompt_) \
_Static_assert(sizeof(name_) <= PROMPT_WIDTH + 1 /*null byte*/, name_ " won't fit in the UI prompt.");

#define ABI_METHOD(selector_, parameters_count_, name_, parameters_...) \
ABI_PARAMETER(name_, ,) \
parameters_

ERC20_ABI
#undef ABI_METHOD
#undef ABI_PARAMETER

#undef ERC20_ABI
#undef ABI_ADDRESS
#undef ABI_AMOUNT
#undef ABI_BYTES32
Loading

0 comments on commit 2694cd1

Please sign in to comment.