Skip to content

Commit

Permalink
Merge fba0613 into 63f9728
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat committed Jun 17, 2020
2 parents 63f9728 + fba0613 commit 9db83f3
Show file tree
Hide file tree
Showing 36 changed files with 906 additions and 81 deletions.
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ trim_trailing_whitespace = true
[*.{md, markdown, eex}]
trim_trailing_whitespace = false

[*.swift]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ wasm-pack.log
**/dist
**/docs
package-lock.json

bindings/ergo-wallet-ios/.build
bindings/ergo-wallet-ios/build
bindings/ergo-wallet-ios/Packages
bindings/ergo-wallet-ios/*.xcodeproj
bindings/ergo-wallet-ios/xcuserdata/
11 changes: 8 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ matrix:
before_script:
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
script:
- cd sigma-wasm
- cd bindings/ergo-wallet-wasm
- wasm-pack build
- wasm-pack test --firefox --headless
- wasm-pack test --firefox --headless --release
Expand All @@ -82,20 +82,25 @@ matrix:
before_script:
- curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -f
script:
- cd sigma-wasm
- cd bindings/ergo-wallet-wasm
- wasm-pack build
- npm install && npm run test

- name: build for iOS
os: osx
osx_image: xcode11.3
osx_image: xcode11.5
rust: stable
before_install:
- rustup target add aarch64-apple-ios x86_64-apple-ios
- cargo install cargo-lipo
- cargo install cbindgen
script:
- cd bindings/ergo-wallet-ios
- cargo lipo --release --targets=aarch64-apple-ios,x86_64-apple-ios
- swift package generate-xcodeproj
- xcodebuild -project ./ErgoWallet.xcodeproj -xcconfig ./Config/Release.xcconfig -sdk iphoneos
- xcodebuild -project ./ErgoWallet.xcodeproj -xcconfig ./Config/Release.xcconfig -sdk iphonesimulator


cache: cargo
# But don't cache the cargo registry
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
members = [
"sigma-ser",
"sigma-tree",
"sigma-wasm",
"sigma-tree-c",
"ergo-wallet",
"bindings/ergo-wallet-wasm",
"bindings/ergo-wallet-c",
"sigma-testutil",
]
10 changes: 7 additions & 3 deletions sigma-tree-c/Cargo.toml → bindings/ergo-wallet-c/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
[package]
name = "sigma-tree-c"
name = "ergo-wallet-c"
version = "0.1.0"
authors = ["Denys Zadorozhnyi <denys@zadorozhnyi.com>"]
edition = "2018"
description = "C bindings for sigma-tree"
description = "Ergo wallet C bindings"
build = "build.rs"

[lib]
crate-type = ["staticlib"]

[dependencies]
sigma-tree = { path = "../sigma-tree", version = "0.1.0" }
ffi_helpers = "0.2"
sigma-tree = { path = "../../sigma-tree"}
ergo-wallet = { path = "../../ergo-wallet"}

[build-dependencies]
cbindgen = "0.14"

[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"
lto = true
15 changes: 15 additions & 0 deletions bindings/ergo-wallet-c/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extern crate cbindgen;

use std::env;

fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let config = cbindgen::Config::from_file("cbindgen.toml").expect("No cbindgen.toml found");

cbindgen::Builder::new()
.with_crate(crate_dir)
.with_config(config)
.generate()
.expect("Unable to generate bindings")
.write_to_file("h/ergo_wallet.h");
}
144 changes: 144 additions & 0 deletions bindings/ergo-wallet-c/cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# This is a template cbindgen.toml file with all of the default values.
# Some values are commented out because their absence is the real default.
#
# See https://github.com/eqrion/cbindgen/blob/master/docs.md#cbindgentoml
# for detailed documentation of every option here.


language = "C"



############## Options for Wrapping the Contents of the Header #################

# header = "/* Text to put at the beginning of the generated file. Probably a license. */"
# trailer = "/* Text to put at the end of the generated file */"
# include_guard = "my_bindings_h"
# pragma_once = true
autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */"
include_version = false
# namespace = "my_namespace"
namespaces = []
using_namespaces = []
sys_includes = []
includes = []
no_includes = false
after_includes = ""




############################ Code Style Options ################################

braces = "SameLine"
line_length = 100
tab_width = 2
documentation_style = "auto"





############################# Codegen Options ##################################

style = "both"



[defines]
# "target_os = freebsd" = "DEFINE_FREEBSD"
# "feature = serde" = "DEFINE_SERDE"



[export]
include = []
exclude = []
# prefix = "CAPI_"
item_types = []
renaming_overrides_prefixing = false



[export.rename]



[export.body]




[fn]
rename_args = "None"
# must_use = "MUST_USE_FUNC"
# prefix = "START_FUNC"
# postfix = "END_FUNC"
args = "auto"
sort_by = "Name"




[struct]
rename_fields = "None"
# must_use = "MUST_USE_STRUCT"
derive_constructor = false
derive_eq = false
derive_neq = false
derive_lt = false
derive_lte = false
derive_gt = false
derive_gte = false




[enum]
rename_variants = "None"
# must_use = "MUST_USE_ENUM"
add_sentinel = false
prefix_with_name = false
derive_helper_methods = false
derive_const_casts = false
derive_mut_casts = false
# cast_assert_name = "ASSERT"
derive_tagged_enum_destructor = false
derive_tagged_enum_copy_constructor = false
enum_class = true
private_default_tagged_enum_constructor = false




[const]
allow_static_const = true
allow_constexpr = false




[macro_expansion]
bitflags = false






############## Options for How Your Rust library Should Be Parsed ##############

[parse]
parse_deps = false
# include = []
exclude = []
clean = false
extra_bindings = []



[parse.expand]
crates = []
all_features = false
default_features = true
features = []
96 changes: 96 additions & 0 deletions bindings/ergo-wallet-c/h/ergo_wallet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */

#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>


typedef struct Address Address;

typedef struct DataInputBoxes DataInputBoxes;

typedef struct ErgoBoxCandidate ErgoBoxCandidate;

typedef struct ErgoStateContext ErgoStateContext;

typedef struct Error Error;

typedef struct OutputBoxes OutputBoxes;

typedef struct Transaction Transaction;

typedef struct UnspentBoxes UnspentBoxes;

typedef struct Wallet Wallet;

typedef Error *ErrorPtr;

typedef Address *AddressPtr;

typedef Transaction *TransactionPtr;

typedef ErgoBoxCandidate *ErgoBoxCandidatePtr;

typedef ErgoStateContext *ErgoStateContextPtr;

typedef OutputBoxes *OutputBoxesPtr;

typedef UnspentBoxes *UnspentBoxesPtr;

typedef Wallet *WalletPtr;

typedef DataInputBoxes *DataInputBoxesPtr;

ErrorPtr ergo_wallet_address_delete(AddressPtr _address);

ErrorPtr ergo_wallet_address_from_testnet(const char *_address_str, AddressPtr *_address_out);

void ergo_wallet_delete_error(ErrorPtr error);

ErrorPtr ergo_wallet_delete_signed_tx(TransactionPtr _transaction);

void ergo_wallet_delete_string(char *ptr);

ErrorPtr ergo_wallet_ergo_box_candidate_delete(ErgoBoxCandidatePtr _ergo_box_candidate);

ErrorPtr ergo_wallet_ergo_box_candidate_new_pay_to_address(AddressPtr _recipient,
uint64_t _value,
uint32_t _creation_height,
ErgoBoxCandidatePtr *_ergo_box_candidate_out);

ErrorPtr ergo_wallet_ergo_state_context_delete(ErgoStateContextPtr _ergo_state_context);

ErrorPtr ergo_wallet_ergo_state_context_from_json(const char *_json_str,
ErgoStateContextPtr *_ergo_state_context_out);

char *ergo_wallet_error_to_string(ErrorPtr error);

ErrorPtr ergo_wallet_output_boxes_delete(OutputBoxesPtr _output_boxes);

ErrorPtr ergo_wallet_output_boxes_new(ErgoBoxCandidatePtr _ergo_box_candidate,
OutputBoxesPtr *_output_boxes_out);

ErrorPtr ergo_wallet_signed_tx_to_json(TransactionPtr _transaction, const char **_json_str_out);

ErrorPtr ergo_wallet_unspent_boxes_delete(UnspentBoxesPtr _unspent_boxes);

ErrorPtr ergo_wallet_unspent_boxes_from_json(const char *_json_str,
UnspentBoxesPtr *_unspent_boxes_out);

ErrorPtr ergo_wallet_wallet_delete(WalletPtr _wallet);

ErrorPtr ergo_wallet_wallet_from_mnemonic(const char *_mnemonic_phrase,
const uint8_t *_mnemonic_password,
uintptr_t _mnemonic_password_length,
WalletPtr *_wallet_out);

ErrorPtr ergo_wallet_wallet_new_signed_tx(WalletPtr _wallet,
ErgoStateContextPtr _state_context,
UnspentBoxesPtr _unspent_boxes,
DataInputBoxesPtr _data_input_boxes,
OutputBoxesPtr _output_boxes,
AddressPtr _send_change_to,
uint64_t _min_change_value,
uint64_t _tx_fee_amount,
TransactionPtr *_transaction_out);
17 changes: 17 additions & 0 deletions bindings/ergo-wallet-c/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::{error, fmt, result};

pub type Result<T> = result::Result<T, Box<dyn error::Error + 'static>>;

#[derive(Debug)]
pub struct Error {
details: Box<dyn error::Error + 'static>,
}

pub type ErrorPtr = *mut Error;

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self.details.as_ref(), f)
}
}

0 comments on commit 9db83f3

Please sign in to comment.