Merge pull request #190 from zcash/rust-crate-updates
Rust crate updates
This commit is contained in:
commit
f6daf3043d
File diff suppressed because it is too large
Load Diff
37
Cargo.toml
37
Cargo.toml
|
@ -9,42 +9,19 @@ build = "rust/build.rs"
|
|||
|
||||
[dependencies]
|
||||
failure = "0.1"
|
||||
ffi_helpers = "0.1"
|
||||
hex = "0.3"
|
||||
|
||||
[dependencies.ff]
|
||||
git = "https://github.com/zcash/librustzcash.git"
|
||||
rev = "18b1ce7401184e86031e6d7ddefa7c8d36929296"
|
||||
|
||||
|
||||
[dependencies.pairing]
|
||||
git = "https://github.com/zcash/librustzcash.git"
|
||||
rev = "18b1ce7401184e86031e6d7ddefa7c8d36929296"
|
||||
|
||||
|
||||
[dependencies.zcash_client_backend]
|
||||
git = "https://github.com/zcash/librustzcash.git"
|
||||
rev = "18b1ce7401184e86031e6d7ddefa7c8d36929296"
|
||||
|
||||
|
||||
[dependencies.zcash_client_sqlite]
|
||||
git = "https://github.com/zcash/librustzcash.git"
|
||||
rev = "18b1ce7401184e86031e6d7ddefa7c8d36929296"
|
||||
|
||||
[dependencies.zcash_primitives]
|
||||
git = "https://github.com/zcash/librustzcash.git"
|
||||
rev = "18b1ce7401184e86031e6d7ddefa7c8d36929296"
|
||||
|
||||
ffi_helpers = "0.2"
|
||||
hex = "0.4"
|
||||
zcash_client_backend = "0.4"
|
||||
zcash_client_sqlite = "0.2"
|
||||
zcash_primitives = "0.4"
|
||||
|
||||
[dependencies.zcash_proofs]
|
||||
git = "https://github.com/zcash/librustzcash.git"
|
||||
rev = "18b1ce7401184e86031e6d7ddefa7c8d36929296"
|
||||
|
||||
version = "0.4"
|
||||
default-features = false
|
||||
features = ["local-prover"]
|
||||
|
||||
[build-dependencies]
|
||||
cbindgen = "0.8"
|
||||
cbindgen = "0.14"
|
||||
|
||||
[lib]
|
||||
name = "zcashlc"
|
||||
|
|
|
@ -2,7 +2,7 @@ platform :ios, '13.0'
|
|||
|
||||
target 'ZcashLightClientSample' do
|
||||
# Comment the next line if you don't want to use dynamic frameworks
|
||||
use_modular_headers!
|
||||
use_frameworks!
|
||||
pod "KRProgressHUD"
|
||||
# Pods for ZcashLightClientSample
|
||||
pod 'ZcashLightClientKit', :path => '../../', :testspecs => ['Tests']
|
||||
|
|
|
@ -66,10 +66,10 @@ PODS:
|
|||
- SwiftNIOFoundationCompat (< 3, >= 2.22.0)
|
||||
- SwiftNIOTLS (< 3, >= 2.22.0)
|
||||
- SwiftProtobuf (1.12.0)
|
||||
- ZcashLightClientKit (0.6.5):
|
||||
- ZcashLightClientKit (0.6.6):
|
||||
- gRPC-Swift (= 1.0.0-alpha.19)
|
||||
- SQLite.swift (~> 0.12.2)
|
||||
- ZcashLightClientKit/Tests (0.6.5):
|
||||
- ZcashLightClientKit/Tests (0.6.6):
|
||||
- gRPC-Swift (= 1.0.0-alpha.19)
|
||||
- SQLite.swift (~> 0.12.2)
|
||||
|
||||
|
@ -145,8 +145,8 @@ SPEC CHECKSUMS:
|
|||
SwiftNIOTLS: 46bb3a0ff37d6b52ae6baf5207ec3cd411da327c
|
||||
SwiftNIOTransportServices: 801923921fbecdcde1e1c1ff38e812167d01ead1
|
||||
SwiftProtobuf: 4ef85479c18ca85b5482b343df9c319c62bda699
|
||||
ZcashLightClientKit: cf07efe70d59e33df138f16f260a48eba6aeb613
|
||||
ZcashLightClientKit: aa2bfedb1cd48385d35113672b521a4bb47fbbf4
|
||||
|
||||
PODFILE CHECKSUM: 1c92e6c09a1a06d8ef4fcf753ebcbe9ea41fb771
|
||||
PODFILE CHECKSUM: db5f48346d4a54b2e0a33adb8890ffba9289ec63
|
||||
|
||||
COCOAPODS: 1.9.3
|
||||
|
|
|
@ -46,9 +46,9 @@
|
|||
0DDFB33C236B743000AED892 /* LatestHeightViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DDFB33B236B743000AED892 /* LatestHeightViewController.swift */; };
|
||||
0DDFB33E236B844900AED892 /* DemoAppConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DDFB33D236B844900AED892 /* DemoAppConfig.swift */; };
|
||||
0DF53E6723A438F100D7249C /* PaginatedTransactionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DF53E6623A438F100D7249C /* PaginatedTransactionsViewController.swift */; };
|
||||
4B7E6D953A7CC9204FDE510C /* Pods_ZcashLightClientSample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6CB06C3C92417F3584991C0B /* Pods_ZcashLightClientSample.framework */; };
|
||||
6355F11E6389A7F4FD9F21F7 /* Pods_ZcashLightClientSample_Mainnet.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49540782BAF7E579947E23C4 /* Pods_ZcashLightClientSample_Mainnet.framework */; };
|
||||
742DCA7AFF9FBEA217FD3EED /* Pods_ZcashLightClientSampleUITests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 33F67E6BA5A27016288E77EB /* Pods_ZcashLightClientSampleUITests.framework */; };
|
||||
8B6C57670F3DC120D19643F4 /* libPods-ZcashLightClientSample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BF3AF259726D0F9D6574293D /* libPods-ZcashLightClientSample.a */; };
|
||||
A459F9A413C2AB70A02FE894 /* Pods_ZcashLightClientSampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C89C3AE14EA6993FECC643BC /* Pods_ZcashLightClientSampleTests.framework */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
|
@ -105,11 +105,11 @@
|
|||
47991618469ABD2A7FE69E73 /* Pods-ZcashLightClientSample-Mainnet.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ZcashLightClientSample-Mainnet.release.xcconfig"; path = "Target Support Files/Pods-ZcashLightClientSample-Mainnet/Pods-ZcashLightClientSample-Mainnet.release.xcconfig"; sourceTree = "<group>"; };
|
||||
49540782BAF7E579947E23C4 /* Pods_ZcashLightClientSample_Mainnet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ZcashLightClientSample_Mainnet.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
501B4B56030ED65B9C170CE2 /* Pods-ZcashLightClientSampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ZcashLightClientSampleTests.debug.xcconfig"; path = "Target Support Files/Pods-ZcashLightClientSampleTests/Pods-ZcashLightClientSampleTests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
6CB06C3C92417F3584991C0B /* Pods_ZcashLightClientSample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ZcashLightClientSample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
81B2AC726EA5CC3FEF521F84 /* Pods-ZcashLightClientSampleUITests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ZcashLightClientSampleUITests.debug.xcconfig"; path = "Target Support Files/Pods-ZcashLightClientSampleUITests/Pods-ZcashLightClientSampleUITests.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
90F55027AEE5406E35644223 /* Pods-ZcashLightClientSample-Mainnet.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ZcashLightClientSample-Mainnet.debug.xcconfig"; path = "Target Support Files/Pods-ZcashLightClientSample-Mainnet/Pods-ZcashLightClientSample-Mainnet.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
93F435FD5C95BEE3BC7BBC28 /* Pods-ZcashLightClientSample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ZcashLightClientSample.debug.xcconfig"; path = "Target Support Files/Pods-ZcashLightClientSample/Pods-ZcashLightClientSample.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
BEA142AE2F3C339269CBA120 /* Pods-ZcashLightClientSampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ZcashLightClientSampleTests.release.xcconfig"; path = "Target Support Files/Pods-ZcashLightClientSampleTests/Pods-ZcashLightClientSampleTests.release.xcconfig"; sourceTree = "<group>"; };
|
||||
BF3AF259726D0F9D6574293D /* libPods-ZcashLightClientSample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ZcashLightClientSample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
C89C3AE14EA6993FECC643BC /* Pods_ZcashLightClientSampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ZcashLightClientSampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
@ -126,7 +126,7 @@
|
|||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8B6C57670F3DC120D19643F4 /* libPods-ZcashLightClientSample.a in Frameworks */,
|
||||
4B7E6D953A7CC9204FDE510C /* Pods_ZcashLightClientSample.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -303,7 +303,7 @@
|
|||
C89C3AE14EA6993FECC643BC /* Pods_ZcashLightClientSampleTests.framework */,
|
||||
33F67E6BA5A27016288E77EB /* Pods_ZcashLightClientSampleUITests.framework */,
|
||||
49540782BAF7E579947E23C4 /* Pods_ZcashLightClientSample_Mainnet.framework */,
|
||||
BF3AF259726D0F9D6574293D /* libPods-ZcashLightClientSample.a */,
|
||||
6CB06C3C92417F3584991C0B /* Pods_ZcashLightClientSample.framework */,
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
|
@ -340,6 +340,7 @@
|
|||
0D907F0E2322CC5900D641FE /* Sources */,
|
||||
0D907F0F2322CC5900D641FE /* Frameworks */,
|
||||
0D907F102322CC5900D641FE /* Resources */,
|
||||
45EC872B9ED4F87BF9B92B1C /* [CP] Embed Pods Frameworks */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
|
@ -552,6 +553,23 @@
|
|||
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
45EC872B9ED4F87BF9B92B1C /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
);
|
||||
inputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-ZcashLightClientSample/Pods-ZcashLightClientSample-frameworks-${CONFIGURATION}-input-files.xcfilelist",
|
||||
);
|
||||
name = "[CP] Embed Pods Frameworks";
|
||||
outputFileListPaths = (
|
||||
"${PODS_ROOT}/Target Support Files/Pods-ZcashLightClientSample/Pods-ZcashLightClientSample-frameworks-${CONFIGURATION}-output-files.xcfilelist",
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-ZcashLightClientSample/Pods-ZcashLightClientSample-frameworks.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
A18B8A4D55F1DF8B808ABB67 /* [CP] Embed Pods Frameworks */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
|
|
10
README.md
10
README.md
|
@ -22,20 +22,10 @@ ZcashLightClientKit uses a rust library called Librustzcash. In order to build i
|
|||
|
||||
Install [Rust](https://www.rust-lang.org/learn/get-started), and then `cargo-lipo`:
|
||||
|
||||
**WORKAROUND**: we are having issues with rustc 1.46.0 we recommend using rustc 1.40.0 until we push a fix for this problem: see issue https://github.com/zcash/ZcashLightClientKit/issues/177
|
||||
|
||||
|
||||
_regular workflow_
|
||||
```
|
||||
$ cargo install cargo-lipo
|
||||
$ rustup target add aarch64-apple-ios x86_64-apple-ios
|
||||
```
|
||||
_workaround to force 1.40.0_
|
||||
```
|
||||
rustup override set 1.40.0
|
||||
rustup target remove aarch64-apple-ios x86_64-apple-ios
|
||||
rustup target add aarch64-apple-ios x86_64-apple-ios
|
||||
```
|
||||
|
||||
# Cocoapods Support
|
||||
|
||||
|
|
|
@ -76,7 +76,8 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
|
||||
static func initAccountsTable(dbData: URL, seed: [UInt8], accounts: Int32) -> [String]? {
|
||||
let dbData = dbData.osStr()
|
||||
let extsksCStr = zcashlc_init_accounts_table(dbData.0, dbData.1, seed, UInt(seed.count), accounts)
|
||||
var capacity = UInt(0);
|
||||
let extsksCStr = zcashlc_init_accounts_table(dbData.0, dbData.1, seed, UInt(seed.count), accounts, &capacity)
|
||||
if extsksCStr == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -85,7 +86,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
guard let str = cStr else { return nil }
|
||||
return String(cString: str)
|
||||
})
|
||||
zcashlc_vec_string_free(extsksCStr, UInt(accounts))
|
||||
zcashlc_vec_string_free(extsksCStr, UInt(accounts), capacity)
|
||||
return extsks
|
||||
}
|
||||
|
||||
|
@ -208,8 +209,8 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
}
|
||||
|
||||
static func deriveExtendedFullViewingKeys(seed: String, accounts: Int32) throws -> [String]? {
|
||||
|
||||
guard let extsksCStr = zcashlc_derive_extended_full_viewing_keys(seed, UInt(seed.lengthOfBytes(using: .utf8)), accounts) else {
|
||||
var capacity = UInt(0);
|
||||
guard let extsksCStr = zcashlc_derive_extended_full_viewing_keys(seed, UInt(seed.lengthOfBytes(using: .utf8)), accounts, &capacity) else {
|
||||
if let error = lastError() {
|
||||
throw error
|
||||
}
|
||||
|
@ -220,12 +221,13 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
guard let str = cStr else { return nil }
|
||||
return String(cString: str)
|
||||
})
|
||||
zcashlc_vec_string_free(extsksCStr, UInt(accounts))
|
||||
zcashlc_vec_string_free(extsksCStr, UInt(accounts), capacity)
|
||||
return extsks
|
||||
}
|
||||
|
||||
static func deriveExtendedSpendingKeys(seed: String, accounts: Int32) throws -> [String]? {
|
||||
guard let extsksCStr = zcashlc_derive_extended_spending_keys(seed, UInt(seed.lengthOfBytes(using: .utf8)), accounts) else {
|
||||
var capacity = UInt(0);
|
||||
guard let extsksCStr = zcashlc_derive_extended_spending_keys(seed, UInt(seed.lengthOfBytes(using: .utf8)), accounts, &capacity) else {
|
||||
if let error = lastError() {
|
||||
throw error
|
||||
}
|
||||
|
@ -236,7 +238,7 @@ class ZcashRustBackend: ZcashRustBackendWelding {
|
|||
guard let str = cStr else { return nil }
|
||||
return String(cString: str)
|
||||
})
|
||||
zcashlc_vec_string_free(extsksCStr, UInt(accounts))
|
||||
zcashlc_vec_string_free(extsksCStr, UInt(accounts), capacity)
|
||||
return extsks
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,11 @@ void zcashlc_clear_last_error(void);
|
|||
|
||||
/**
|
||||
* Creates a transaction paying the specified address from the given account.
|
||||
*
|
||||
* Returns the row index of the newly-created transaction in the `transactions` table
|
||||
* within the data database. The caller can read the raw transaction bytes from the `raw`
|
||||
* column in order to broadcast the transaction to the network.
|
||||
*
|
||||
* Do not call this multiple times in parallel, or you will generate transactions that
|
||||
* double-spend the same notes.
|
||||
*/
|
||||
|
@ -40,11 +42,13 @@ char *zcashlc_derive_extended_full_viewing_key(const char *extsk);
|
|||
|
||||
char **zcashlc_derive_extended_full_viewing_keys(const uint8_t *seed,
|
||||
uintptr_t seed_len,
|
||||
int32_t accounts);
|
||||
int32_t accounts,
|
||||
uintptr_t *capacity_ret);
|
||||
|
||||
char **zcashlc_derive_extended_spending_keys(const uint8_t *seed,
|
||||
uintptr_t seed_len,
|
||||
int32_t accounts);
|
||||
int32_t accounts,
|
||||
uintptr_t *capacity_ret);
|
||||
|
||||
/**
|
||||
* Copies the last error message into the provided allocated buffer.
|
||||
|
@ -53,6 +57,7 @@ int32_t zcashlc_error_message_utf8(char *buf, int32_t length);
|
|||
|
||||
/**
|
||||
* Returns the address for the account.
|
||||
*
|
||||
* Call `zcashlc_string_free` on the returned pointer when you are finished with it.
|
||||
*/
|
||||
char *zcashlc_get_address(const uint8_t *db_data, uintptr_t db_data_len, int32_t account);
|
||||
|
@ -64,8 +69,10 @@ int64_t zcashlc_get_balance(const uint8_t *db_data, uintptr_t db_data_len, int32
|
|||
|
||||
/**
|
||||
* Returns the memo for a received note, if it is known and a valid UTF-8 string.
|
||||
*
|
||||
* The note is identified by its row index in the `received_notes` table within the data
|
||||
* database.
|
||||
*
|
||||
* Call `zcashlc_string_free` on the returned pointer when you are finished with it.
|
||||
*/
|
||||
char *zcashlc_get_received_memo_as_utf8(const uint8_t *db_data,
|
||||
|
@ -74,8 +81,10 @@ char *zcashlc_get_received_memo_as_utf8(const uint8_t *db_data,
|
|||
|
||||
/**
|
||||
* Returns the memo for a sent note, if it is known and a valid UTF-8 string.
|
||||
*
|
||||
* The note is identified by its row index in the `sent_notes` table within the data
|
||||
* database.
|
||||
*
|
||||
* Call `zcashlc_string_free` on the returned pointer when you are finished with it.
|
||||
*/
|
||||
char *zcashlc_get_sent_memo_as_utf8(const uint8_t *db_data, uintptr_t db_data_len, int64_t id_note);
|
||||
|
@ -90,18 +99,22 @@ int64_t zcashlc_get_verified_balance(const uint8_t *db_data,
|
|||
|
||||
/**
|
||||
* Initialises the data database with the given number of accounts using the given seed.
|
||||
*
|
||||
* Returns the ExtendedSpendingKeys for the accounts. The caller should store these
|
||||
* securely for use while spending.
|
||||
*
|
||||
* Call `zcashlc_vec_string_free` on the returned pointer when you are finished with it.
|
||||
*/
|
||||
char **zcashlc_init_accounts_table(const uint8_t *db_data,
|
||||
uintptr_t db_data_len,
|
||||
const uint8_t *seed,
|
||||
uintptr_t seed_len,
|
||||
int32_t accounts);
|
||||
int32_t accounts,
|
||||
uintptr_t *capacity_ret);
|
||||
|
||||
/**
|
||||
* Initialises the data database with the given block.
|
||||
*
|
||||
* This enables a newly-created database to be immediately-usable, without needing to
|
||||
* synchronise historic blocks.
|
||||
*/
|
||||
|
@ -137,6 +150,7 @@ int32_t zcashlc_last_error_length(void);
|
|||
|
||||
/**
|
||||
* Rewinds the data database to the given height.
|
||||
*
|
||||
* If the requested height is greater than or equal to the height of the last scanned
|
||||
* block, this function does nothing.
|
||||
*/
|
||||
|
@ -145,13 +159,16 @@ int32_t zcashlc_rewind_to_height(const uint8_t *db_data, uintptr_t db_data_len,
|
|||
/**
|
||||
* Scans new blocks added to the cache for any transactions received by the tracked
|
||||
* accounts.
|
||||
*
|
||||
* This function pays attention only to cached blocks with heights greater than the
|
||||
* highest scanned block in `db_data`. Cached blocks with lower heights are not verified
|
||||
* against previously-scanned blocks. In particular, this function **assumes** that the
|
||||
* caller is handling rollbacks.
|
||||
*
|
||||
* For brand-new light client databases, this function starts scanning from the Sapling
|
||||
* activation height. This height can be fast-forwarded to a more recent block by calling
|
||||
* [`zcashlc_init_blocks_table`] before this function.
|
||||
*
|
||||
* Scanned blocks are required to be height-sequential. If a block is missing from the
|
||||
* cache, an error will be signalled.
|
||||
*/
|
||||
|
@ -168,16 +185,19 @@ void zcashlc_string_free(char *s);
|
|||
/**
|
||||
* Checks that the scanned blocks in the data database, when combined with the recent
|
||||
* `CompactBlock`s in the cache database, form a valid chain.
|
||||
*
|
||||
* This function is built on the core assumption that the information provided in the
|
||||
* cache database is more likely to be accurate than the previously-scanned information.
|
||||
* This follows from the design (and trust) assumption that the `lightwalletd` server
|
||||
* provides accurate block information as of the time it was requested.
|
||||
*
|
||||
* Returns:
|
||||
* - `-1` if the combined chain is valid.
|
||||
* - `upper_bound` if the combined chain is invalid.
|
||||
* `upper_bound` is the height of the highest invalid block (on the assumption that the
|
||||
* highest block in the cache database is correct).
|
||||
* `upper_bound` is the height of the highest invalid block (on the assumption that the
|
||||
* highest block in the cache database is correct).
|
||||
* - `0` if there was an error during validation unrelated to chain validity.
|
||||
*
|
||||
* This function does not mutate either of the databases.
|
||||
*/
|
||||
int32_t zcashlc_validate_combined_chain(const uint8_t *db_cache,
|
||||
|
@ -188,4 +208,4 @@ int32_t zcashlc_validate_combined_chain(const uint8_t *db_cache,
|
|||
/**
|
||||
* Frees vectors of strings returned by other zcashlc functions.
|
||||
*/
|
||||
void zcashlc_vec_string_free(char **v, uintptr_t len);
|
||||
void zcashlc_vec_string_free(char **v, uintptr_t len, uintptr_t capacity);
|
||||
|
|
|
@ -23,8 +23,7 @@ use zcash_client_sqlite::{
|
|||
get_verified_balance,
|
||||
},
|
||||
scan::{decrypt_and_store_transaction, scan_cached_blocks},
|
||||
transact::{create_to_address, OvkPolicy}
|
||||
|
||||
transact::{create_to_address, OvkPolicy},
|
||||
};
|
||||
use zcash_primitives::{
|
||||
block::BlockHash,
|
||||
|
@ -115,6 +114,7 @@ pub extern "C" fn zcashlc_init_accounts_table(
|
|||
seed: *const u8,
|
||||
seed_len: usize,
|
||||
accounts: i32,
|
||||
capacity_ret: *mut usize,
|
||||
) -> *mut *mut c_char {
|
||||
let res = catch_panic(|| {
|
||||
let db_data = Path::new(OsStr::from_bytes(unsafe {
|
||||
|
@ -151,7 +151,8 @@ pub extern "C" fn zcashlc_init_accounts_table(
|
|||
CString::new(encoded).unwrap().into_raw()
|
||||
})
|
||||
.collect();
|
||||
assert!(v.len() == v.capacity());
|
||||
assert!(v.len() == accounts as usize);
|
||||
unsafe { *capacity_ret.as_mut().unwrap() = v.capacity() };
|
||||
let p = v.as_mut_ptr();
|
||||
std::mem::forget(v);
|
||||
Ok(p)
|
||||
|
@ -197,6 +198,7 @@ pub unsafe extern "C" fn zcashlc_derive_extended_spending_keys(
|
|||
seed: *const u8,
|
||||
seed_len: usize,
|
||||
accounts: i32,
|
||||
capacity_ret: *mut usize,
|
||||
) -> *mut *mut c_char {
|
||||
let res = catch_panic(|| {
|
||||
let seed = slice::from_raw_parts(seed, seed_len);
|
||||
|
@ -219,7 +221,8 @@ pub unsafe extern "C" fn zcashlc_derive_extended_spending_keys(
|
|||
CString::new(encoded).unwrap().into_raw()
|
||||
})
|
||||
.collect();
|
||||
assert!(v.len() == v.capacity());
|
||||
assert!(v.len() == accounts as usize);
|
||||
*capacity_ret.as_mut().unwrap() = v.capacity();
|
||||
let p = v.as_mut_ptr();
|
||||
std::mem::forget(v);
|
||||
Ok(p)
|
||||
|
@ -232,6 +235,7 @@ pub unsafe extern "C" fn zcashlc_derive_extended_full_viewing_keys(
|
|||
seed: *const u8,
|
||||
seed_len: usize,
|
||||
accounts: i32,
|
||||
capacity_ret: *mut usize,
|
||||
) -> *mut *mut c_char {
|
||||
let res = catch_panic(|| {
|
||||
let seed = slice::from_raw_parts(seed, seed_len);
|
||||
|
@ -254,7 +258,8 @@ pub unsafe extern "C" fn zcashlc_derive_extended_full_viewing_keys(
|
|||
CString::new(encoded).unwrap().into_raw()
|
||||
})
|
||||
.collect();
|
||||
assert!(v.len() == v.capacity());
|
||||
assert!(v.len() == accounts as usize);
|
||||
*capacity_ret.as_mut().unwrap() = v.capacity();
|
||||
let p = v.as_mut_ptr();
|
||||
std::mem::forget(v);
|
||||
Ok(p)
|
||||
|
@ -611,7 +616,6 @@ pub extern "C" fn zcashlc_create_to_address(
|
|||
output_params_len: usize,
|
||||
) -> i64 {
|
||||
let res = catch_panic(|| {
|
||||
|
||||
let branch_id = match BranchId::try_from(consensus_branch_id as u32) {
|
||||
Ok(extsk) => extsk,
|
||||
Err(e) => {
|
||||
|
@ -671,7 +675,7 @@ pub extern "C" fn zcashlc_create_to_address(
|
|||
&to,
|
||||
value,
|
||||
Some(memo),
|
||||
OvkPolicy::Sender
|
||||
OvkPolicy::Sender,
|
||||
)
|
||||
.map_err(|e| format_err!("Error while sending funds: {}", e))
|
||||
});
|
||||
|
@ -679,14 +683,12 @@ pub extern "C" fn zcashlc_create_to_address(
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn zcashlc_branch_id_for_height(
|
||||
height: i32,
|
||||
) -> i32 {
|
||||
pub extern "C" fn zcashlc_branch_id_for_height(height: i32) -> i32 {
|
||||
let res = catch_panic(|| {
|
||||
let branch: BranchId = BranchId::for_height::<Network>(height as u32);
|
||||
let branch_id:u32 = u32::from(branch);
|
||||
let branch_id: u32 = u32::from(branch);
|
||||
Ok(branch_id as i32)
|
||||
});
|
||||
});
|
||||
unwrap_exc_or(res, -1)
|
||||
}
|
||||
|
||||
|
@ -703,13 +705,13 @@ pub extern "C" fn zcashlc_string_free(s: *mut c_char) {
|
|||
|
||||
/// Frees vectors of strings returned by other zcashlc functions.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn zcashlc_vec_string_free(v: *mut *mut c_char, len: usize) {
|
||||
pub extern "C" fn zcashlc_vec_string_free(v: *mut *mut c_char, len: usize, capacity: usize) {
|
||||
unsafe {
|
||||
if v.is_null() {
|
||||
return;
|
||||
}
|
||||
// All Vecs created by other functions MUST have length == capacity.
|
||||
let v = Vec::from_raw_parts(v, len, len);
|
||||
assert!(len <= capacity);
|
||||
let v = Vec::from_raw_parts(v, len, capacity);
|
||||
v.into_iter().map(|s| CString::from_raw(s)).for_each(drop);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue