Skip to content

Commit 5bedb64

Browse files
committed
feat: update createTx
1 parent 27be042 commit 5bedb64

File tree

10 files changed

+61
-62
lines changed

10 files changed

+61
-62
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55

66
jobs:
77
build:
8-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-22.04
99
steps:
10-
- uses: actions/checkout@v2
10+
- uses: actions/checkout@v4
1111
- name: Download Boost
1212
run: |
13-
wget --progress=dot:mega https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz
13+
wget --progress=dot:mega https://archives.boost.io/release/1.76.0/source/boost_1_76_0.tar.gz
1414
mkdir -p ./contrib/boost-sdk
1515
tar zxf 'boost_1_76_0.tar.gz' -C './contrib/boost-sdk' --strip-components=1
1616
- name: Build Boost
@@ -32,7 +32,7 @@ jobs:
3232
--env BUILD=production \
3333
--env WASM=0 \
3434
-v $(pwd):/src emscripten/emsdk:2.0.20 ./bin/build-emcpp.sh
35-
- uses: actions/upload-artifact@v2
35+
- uses: actions/upload-artifact@v4
3636
with:
3737
name: wasm
3838
path: |
@@ -42,32 +42,32 @@ jobs:
4242
4343
test:
4444
needs: build
45-
runs-on: ubuntu-20.04
45+
runs-on: ubuntu-22.04
4646
steps:
47-
- uses: actions/checkout@v2
48-
- uses: actions/download-artifact@v2
47+
- uses: actions/checkout@v4
48+
- uses: actions/download-artifact@v5
4949
with:
5050
name: wasm
5151
path: build
52-
- uses: actions/setup-node@v2
52+
- uses: actions/setup-node@v4
5353
with:
54-
node-version: 16
54+
node-version: 20
5555
- run: npm ci
5656
- run: npm test
5757

5858
publish:
5959
needs: test
60-
runs-on: ubuntu-20.04
60+
runs-on: ubuntu-22.04
6161
if: startsWith(github.ref, 'refs/tags/v')
6262
steps:
63-
- uses: actions/checkout@v2
64-
- uses: actions/download-artifact@v2
63+
- uses: actions/checkout@v4
64+
- uses: actions/download-artifact@v5
6565
with:
6666
name: wasm
6767
path: build
68-
- uses: actions/setup-node@v2
68+
- uses: actions/setup-node@v4
6969
with:
70-
node-version: 16
70+
node-version: 20
7171
registry-url: https://npm.pkg.github.com/
7272
- run: npm publish --access public
7373
env:

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
16.15.0
1+
20.11.1

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM emscripten/emsdk:2.0.20
22

3-
RUN wget --progress=dot:mega https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.gz && \
3+
RUN wget --progress=dot:mega https://archives.boost.io/release/1.76.0/source/boost_1_76_0.tar.gz && \
44
mkdir -p ./contrib/boost-sdk && \
55
tar zxf 'boost_1_76_0.tar.gz' -C './contrib/boost-sdk' --strip-components=1 && \
66
rm -f boost_1_76_0.tar.gz

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ JS library for creating Monero transactions.
1111
```
1212
docker-compose build
1313
docker-compose up -d
14-
docker exec -it monero-core-js-emscripten-1 cp -r /src/build /app
15-
docker exec -it monero-core-js-emscripten-1 ./bin/build-emcpp.sh
14+
docker exec -it monero-core-js_emscripten_1 cp -r /src/build /app
15+
docker exec -it monero-core-js_emscripten_1 ./bin/build-emcpp.sh
1616
1717
npm install
1818
npm test
@@ -22,13 +22,11 @@ npm test
2222

2323
Install https://goo.gle/wasm-debugging-extension and set Path substitutions in extension options:
2424
```
25-
Module: MyMoneroCoreCpp_WASM.wasm
25+
Module: MoneroCoreJS.wasm
2626
/app
2727
[path_to_monero_core_js]
2828
```
2929

30-
Open Chrome DevTools, click the gear (⚙) icon in the top right corner of DevTools pane, go to the Experiments panel and tick WebAssembly Debugging: Enable DWARF support.
31-
3230
```
3331
npm run serve
3432
npm run serve:wasm

docker-compose.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,4 @@ services:
99
BUILD: debug
1010
working_dir: /app
1111
volumes:
12-
- code:/app
13-
14-
volumes:
15-
code: # https://github.com/docker/for-mac/issues/3677#issuecomment-620040545
16-
driver: local
17-
driver_opts:
18-
type: nfs
19-
o: addr=host.docker.internal,rw,nolock,hard,nointr
20-
device: ":${PWD}"
12+
- ./:/app

package-lock.json

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#include <stdio.h>
22
#include <emscripten/bind.h>
3+
#include <emscripten/val.h>
34
#include "monero_core.hpp"
45

56
using namespace std;
67

7-
string createTx(const string& args_string) {
8-
string result = monero_core::createTx(args_string);
9-
return result.c_str();
8+
emscripten::val createTx(const string& args_string) {
9+
monero_core::CreateTxResult result = monero_core::createTx(args_string);
10+
emscripten::val obj = emscripten::val::object();
11+
obj.set("rawTx", result.raw_tx);
12+
obj.set("txKey", result.tx_key);
13+
return obj;
1014
}
1115

1216
string getExceptionMessage(intptr_t exceptionPtr) {

src/monero_core.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ rct::RCTConfig get_rct_config() {
173173
return rct_config;
174174
}
175175

176-
string monero_core::createTx(const string &args_string) {
176+
CreateTxResult monero_core::createTx(const string &args_string) {
177177

178178
boost::property_tree::ptree json_root;
179179
istringstream ss(args_string);
@@ -229,6 +229,8 @@ string monero_core::createTx(const string &args_string) {
229229
if (!r) throw std::runtime_error("Error from construct_tx_and_get_tx_key");
230230
// string tx_hash_string = epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(tx));
231231
// printf("tx_hash_string: %s\n", tx_hash_string.c_str());
232-
string signed_serialized_tx_string = epee::string_tools::buff_to_hex_nodelimer(cryptonote::tx_to_blob(tx));
233-
return signed_serialized_tx_string;
232+
CreateTxResult result;
233+
result.raw_tx = epee::string_tools::buff_to_hex_nodelimer(cryptonote::tx_to_blob(tx));
234+
result.tx_key = epee::string_tools::pod_to_hex(unwrap(unwrap(tx_key)));
235+
return result;
234236
}

src/monero_core.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ namespace monero_core {
3333
std::vector<RandomAmountOutput> outputs;
3434
};
3535

36-
std::string createTx(const std::string &args_string);
36+
struct CreateTxResult {
37+
std::string raw_tx;
38+
std::string tx_key;
39+
};
40+
41+
CreateTxResult createTx(const std::string &args_string);
3742
}
3843

3944
#endif /* monero_core_hpp */

test/index.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,62 @@
33
const assert = require('assert');
44
const initMoneroCoreJs = require('../index.js');
55
const [standard, subaddress, integrated] = require('./fixtures/data.json');
6+
WebAssembly.instantiateStreaming = false;
67

78
describe('index', () => {
89

910
describe('createTx (wasm)', () => {
1011
it('should work (standard address)', async () => {
1112
const moneroCoreJs = await initMoneroCoreJs();
12-
const rawTx = moneroCoreJs.createTx(standard);
13+
const { rawTx, txKey } = moneroCoreJs.createTx(standard);
1314
assert.strictEqual(typeof rawTx, 'string');
1415
assert.ok(rawTx.length > 0);
16+
assert.strictEqual(typeof txKey, 'string');
17+
assert.ok(txKey.length > 0);
1518
});
1619
it('should work wasm (subaddress address)', async () => {
1720
const moneroCoreJs = await initMoneroCoreJs();
18-
const rawTx = moneroCoreJs.createTx(subaddress);
21+
const { rawTx, txKey } = moneroCoreJs.createTx(subaddress);
1922
assert.strictEqual(typeof rawTx, 'string');
2023
assert.ok(rawTx.length > 0);
24+
assert.strictEqual(typeof txKey, 'string');
25+
assert.ok(txKey.length > 0);
2126
});
2227
it('should work wasm (integrated address)', async () => {
2328
const moneroCoreJs = await initMoneroCoreJs();
24-
const rawTx = moneroCoreJs.createTx(integrated);
29+
const { rawTx, txKey } = moneroCoreJs.createTx(integrated);
2530
assert.strictEqual(typeof rawTx, 'string');
2631
assert.ok(rawTx.length > 0);
32+
assert.strictEqual(typeof txKey, 'string');
33+
assert.ok(txKey.length > 0);
2734
});
2835
});
2936

3037
describe('createTx (asm)', () => {
3138
it('should work asm (standard address)', async () => {
3239
const moneroCoreJs = await initMoneroCoreJs(false, true);
33-
const rawTx = moneroCoreJs.createTx(standard);
40+
const { rawTx, txKey } = moneroCoreJs.createTx(standard);
3441
assert.strictEqual(typeof rawTx, 'string');
3542
assert.ok(rawTx.length > 0);
43+
assert.strictEqual(typeof txKey, 'string');
44+
assert.ok(txKey.length > 0);
3645
});
3746
it('should work asm (subaddress address)', async () => {
3847
const moneroCoreJs = await initMoneroCoreJs(false, true);
39-
const rawTx = moneroCoreJs.createTx(subaddress);
48+
const { rawTx, txKey } = moneroCoreJs.createTx(subaddress);
4049
assert.strictEqual(typeof rawTx, 'string');
4150
assert.ok(rawTx.length > 0);
51+
assert.strictEqual(typeof txKey, 'string');
52+
assert.ok(txKey.length > 0);
4253
});
4354
it('should work asm (integrated address)', async () => {
4455
const moneroCoreJs = await initMoneroCoreJs(false, true);
45-
const rawTx = moneroCoreJs.createTx(integrated);
56+
const { rawTx, txKey } = moneroCoreJs.createTx(integrated);
4657
assert.strictEqual(typeof rawTx, 'string');
4758
assert.ok(rawTx.length > 0);
59+
assert.strictEqual(typeof txKey, 'string');
60+
assert.ok(txKey.length > 0);
4861
});
4962
});
5063

51-
// describe('createTx (BulletproofPlus)', () => {
52-
// it('should work wasm', async () => {
53-
// const moneroCoreJs = await initMoneroCoreJs();
54-
// CLSAG.forEach((fixture) => {
55-
// const rawTx = moneroCoreJs.createTx(fixture);
56-
// assert.strictEqual(typeof rawTx, 'string');
57-
// assert.ok(rawTx.length > 0);
58-
// });
59-
// });
60-
// it('should work asm', async () => {
61-
// const moneroCoreJs = await initMoneroCoreJs(false, true);
62-
// CLSAG.forEach((fixture) => {
63-
// const rawTx = moneroCoreJs.createTx(fixture);
64-
// assert.strictEqual(typeof rawTx, 'string');
65-
// assert.ok(rawTx.length > 0);
66-
// });
67-
// });
68-
// });
69-
7064
});

0 commit comments

Comments
 (0)