From cb3edacd637d8a4830c9880b7fd70eda411d8481 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Tue, 7 Jun 2022 11:23:58 +0000 Subject: [PATCH] fix variable emit details size in example hooks --- hook/examples/accept/accept.c | 1 + hook/examples/accept/makefile | 3 ++- hook/examples/carbon/carbon.c | 1 + hook/examples/carbon/makefile | 4 ++-- hook/examples/doubler/makefile | 3 ++- hook/examples/doubler/pay.js | 2 +- hook/examples/macro.h | 19 ++++++++++++++----- hook/examples/notary/makefile | 3 ++- 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hook/examples/accept/accept.c b/hook/examples/accept/accept.c index 1c48fbda0..471958f85 100644 --- a/hook/examples/accept/accept.c +++ b/hook/examples/accept/accept.c @@ -1,6 +1,7 @@ /** * This hook just accepts any transaction coming through it */ +#define HAS_CALLBACK #include "../hookapi.h" int64_t cbak(uint32_t reserved) { diff --git a/hook/examples/accept/makefile b/hook/examples/accept/makefile index 829a0b5ea..9a3f2d2ea 100644 --- a/hook/examples/accept/makefile +++ b/hook/examples/accept/makefile @@ -1,4 +1,5 @@ all: - wasmcc accept.c -o accept.wasm -O0 -Wl,--allow-undefined -I../ + wasmcc accept.c -o /tmp/accept.wasm -O0 -Wl,--allow-undefined -I../ + wasm-opt -O2 /tmp/accept.wasm -o accept.wasm hook-cleaner accept.wasm diff --git a/hook/examples/carbon/carbon.c b/hook/examples/carbon/carbon.c index 2fdb0b467..af0247e42 100644 --- a/hook/examples/carbon/carbon.c +++ b/hook/examples/carbon/carbon.c @@ -1,3 +1,4 @@ +#define HAS_CALLBACK #include #include "hookapi.h" diff --git a/hook/examples/carbon/makefile b/hook/examples/carbon/makefile index f3f93053b..442bc6fab 100644 --- a/hook/examples/carbon/makefile +++ b/hook/examples/carbon/makefile @@ -1,5 +1,5 @@ all: - wasmcc carbon.c -o carbon.wasm -O2 -Wl,--allow-undefined -I../ + wasmcc carbon.c -o /tmp/carbon.wasm -O0 -Wl,--allow-undefined -I../ + wasm-opt -O2 /tmp/carbon.wasm -o carbon.wasm hook-cleaner carbon.wasm - diff --git a/hook/examples/doubler/makefile b/hook/examples/doubler/makefile index e8280314d..2244fc66f 100644 --- a/hook/examples/doubler/makefile +++ b/hook/examples/doubler/makefile @@ -1,4 +1,5 @@ all: - wasmcc doubler.c -o doubler.wasm -O2 -Wl,--allow-undefined -I../ + wasmcc doubler.c -o /tmp/doubler.wasm -O0 -Wl,--allow-undefined -I../ + wasm-opt -O2 /tmp/doubler.wasm -o doubler.wasm hook-cleaner doubler.wasm diff --git a/hook/examples/doubler/pay.js b/hook/examples/doubler/pay.js index 3cfe9aed7..8165fcf28 100644 --- a/hook/examples/doubler/pay.js +++ b/hook/examples/doubler/pay.js @@ -7,7 +7,7 @@ const secret = process.argv[2]; const amount = BigInt(process.argv[3]) * 1000000n const dest = process.argv[4]; -require('../utils-tests.js').TestRig('ws://localhost:6005').then(t=> +require('../../utils-tests.js').TestRig('ws://localhost:6005').then(t=> { t.pay(secret, amount, dest).then(x=> { diff --git a/hook/examples/macro.h b/hook/examples/macro.h index 1b54df5c7..9a0e68fac 100644 --- a/hook/examples/macro.h +++ b/hook/examples/macro.h @@ -481,7 +481,12 @@ int out_len = 0;\ ENCODE_SIGNING_PUBKEY_NULL(buf_out ); -#define PREPARE_PAYMENT_SIMPLE_SIZE 270 +#ifdef HAS_CALLBACK +#define PREPARE_PAYMENT_SIMPLE_SIZE 270U +#else +#define PREPARE_PAYMENT_SIMPLE_SIZE 248U +#endif + #define PREPARE_PAYMENT_SIMPLE(buf_out_master, drops_amount_raw, to_address, dest_tag_raw, src_tag_raw)\ {\ uint8_t* buf_out = buf_out_master;\ @@ -504,12 +509,16 @@ int out_len = 0;\ _07_03_ENCODE_SIGNING_PUBKEY_NULL (buf_out ); /* pk | size 35 */ \ _08_01_ENCODE_ACCOUNT_SRC (buf_out, acc ); /* account | size 22 */ \ _08_03_ENCODE_ACCOUNT_DST (buf_out, to_address ); /* account | size 22 */ \ - etxn_details((uint32_t)buf_out, 138); /* emitdet | size 138 */ \ - int64_t fee = etxn_fee_base(buf_out_master, 270); \ + int64_t edlen = etxn_details((uint32_t)buf_out, PREPARE_PAYMENT_SIMPLE_SIZE); /* emitdet | size 1?? */ \ + int64_t fee = etxn_fee_base(buf_out_master, PREPARE_PAYMENT_SIMPLE_SIZE); \ _06_08_ENCODE_DROPS_FEE (fee_ptr, fee ); \ } +#ifdef HAS_CALLBACK #define PREPARE_PAYMENT_SIMPLE_TRUSTLINE_SIZE 309 +#else +#define PREPARE_PAYMENT_SIMPLE_TRUSTLINE_SIZE 287 +#endif #define PREPARE_PAYMENT_SIMPLE_TRUSTLINE(buf_out_master, tlamt, drops_fee_raw, to_address, dest_tag_raw, src_tag_raw)\ {\ uint8_t* buf_out = buf_out_master;\ @@ -532,8 +541,8 @@ int out_len = 0;\ _07_03_ENCODE_SIGNING_PUBKEY_NULL (buf_out ); /* pk | size 35 */ \ _08_01_ENCODE_ACCOUNT_SRC (buf_out, acc ); /* account | size 22 */ \ _08_03_ENCODE_ACCOUNT_DST (buf_out, to_address ); /* account | size 22 */ \ - etxn_details((uint32_t)buf_out, 138); /* emitdet | size 138 */ \ - int64_t fee = etxn_fee_base(buf_out_master, 309); \ + etxn_details((uint32_t)buf_out, PREPARE_PAYMENT_SIMPLE_TRUSTLINE_SIZE); /* emitdet | size 1?? */ \ + int64_t fee = etxn_fee_base(buf_out_master, PREPARE_PAYMENT_SIMPLE_TRUSTLINE_SIZE); \ _06_08_ENCODE_DROPS_FEE (fee_ptr, fee ); \ } diff --git a/hook/examples/notary/makefile b/hook/examples/notary/makefile index 09b61cd71..16af9be48 100644 --- a/hook/examples/notary/makefile +++ b/hook/examples/notary/makefile @@ -1,4 +1,5 @@ all: - wasmcc notary.c -o notary.wasm -O0 -Wl,--allow-undefined -I../ + wasmcc notary.c -o /tmp/notary.wasm -O0 -Wl,--allow-undefined -I../ + wasm-opt -O2 /tmp/notary.wasm -o notary.wasm hook-cleaner notary.wasm