mirror of
https://github.com/MAGICGrants/flutter_libsparkmobile.git
synced 2026-01-06 19:53:57 -05:00
pull structs in separate header
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -26,6 +26,10 @@ doc/api/
|
||||
.flutter-plugins
|
||||
.flutter-plugins-dependencies
|
||||
|
||||
# IntelliJ related
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
.idea/
|
||||
|
||||
example/ios/Podfile.lock
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/sparkmobile/secp256k1/src/java" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/linux/flutter/ephemeral" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/macos/Flutter/ephemeral" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/macos/Runner.xcodeproj/xcuserdata" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/macos/Runner.xcworkspace/xcuserdata" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/macos/Pods" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/example/windows/flutter/ephemeral" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/macos/flutter_libsparkmobile.framework" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/scripts/macos/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/src/build" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Dart SDK" level="project" />
|
||||
<orderEntry type="library" name="Flutter Plugins" level="project" />
|
||||
<orderEntry type="library" name="Dart Packages" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "flutter_libsparkmobile.h"
|
||||
#include "utils.h"
|
||||
#include "deps/sparkmobile/include/spark.h"
|
||||
#include "deps/sparkmobile/bitcoin/uint256.h"
|
||||
#include "structs.h"
|
||||
|
||||
#include <cstring>
|
||||
#include "deps/sparkmobile/bitcoin/uint256.h"
|
||||
#include <iostream> // Just for printing.
|
||||
|
||||
using namespace spark;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define ORG_FIRO_SPARK_DART_INTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "structs.h"
|
||||
|
||||
#ifndef FFI_PLUGIN_EXPORT
|
||||
#ifdef __cplusplus
|
||||
@@ -25,38 +26,6 @@ FFI_PLUGIN_EXPORT
|
||||
const char* createIncomingViewKey(const char* keyData, int index);
|
||||
*/
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::Coin.
|
||||
*
|
||||
* Coin: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/coin.h#L66
|
||||
*/
|
||||
struct CCoin {
|
||||
char type;
|
||||
const unsigned char* k;
|
||||
int kLength;
|
||||
const char* address;
|
||||
uint64_t v;
|
||||
const unsigned char* memo;
|
||||
int memoLength;
|
||||
const unsigned char* serial_context;
|
||||
int serial_contextLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::IdentifiedCoinData.
|
||||
*
|
||||
* IdentifiedCoinData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/coin.h#L19
|
||||
*/
|
||||
struct CIdentifiedCoinData {
|
||||
uint64_t i;
|
||||
const unsigned char* d;
|
||||
int dLength;
|
||||
uint64_t v;
|
||||
const unsigned char* k;
|
||||
int kLength;
|
||||
const char* memo;
|
||||
int memoLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for spark::identifyCoin.
|
||||
@@ -66,33 +35,6 @@ struct CIdentifiedCoinData {
|
||||
FFI_PLUGIN_EXPORT
|
||||
struct CIdentifiedCoinData identifyCoin(struct CCoin c_struct, const char* keyDataHex, int index);
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::CRecipient.
|
||||
*
|
||||
* CRecipient: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/include/spark.h#L27
|
||||
*/
|
||||
struct CCRecipient {
|
||||
const unsigned char* pubKey;
|
||||
int pubKeyLength;
|
||||
uint64_t cAmount;
|
||||
int subtractFee;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::MintedCoinData.
|
||||
*
|
||||
* MintedCoinData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/mint_transaction.h#L12
|
||||
*/
|
||||
struct CMintedCoinData {
|
||||
const char* address;
|
||||
uint64_t value;
|
||||
const char* memo;
|
||||
};
|
||||
|
||||
struct PubKeyScript {
|
||||
unsigned char* bytes;
|
||||
int length;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for spark::createSparkMintRecipients.
|
||||
@@ -107,94 +49,6 @@ struct CCRecipient* createSparkMintRecipients(
|
||||
int serial_contextLength,
|
||||
int generate);
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a std::pair<CAmount, bool>.
|
||||
*
|
||||
* Note this is an ambiguation of a spark::CRecipient. This CRecip(ient) is just a wrapper for a
|
||||
* CAmount and bool pair, and is not the same as the spark::CRecipient struct above, which gets
|
||||
* wrapped for us as a CCRecipient and is unrelated to this struct.
|
||||
*
|
||||
* See https://github.com/firoorg/sparkmobile/blob/23099b0d9010a970ad75b9cfe05d568d634088f3/src/spark.cpp#L190
|
||||
*/
|
||||
struct CRecip {
|
||||
uint64_t amount;
|
||||
int subtractFee;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::OutputCoinData.
|
||||
*
|
||||
* OutputCoinData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/spend_transaction.h#L33
|
||||
*/
|
||||
struct COutputCoinData {
|
||||
const char* address;
|
||||
uint64_t value;
|
||||
const char* memo;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a <spark::OutputCoinData, bool>.
|
||||
*
|
||||
* See https://github.com/firoorg/sparkmobile/blob/23099b0d9010a970ad75b9cfe05d568d634088f3/src/spark.cpp#L195
|
||||
*/
|
||||
struct COutputRecipient {
|
||||
struct COutputCoinData output;
|
||||
int subtractFee;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::CSparkMintMeta.
|
||||
*
|
||||
* CSparkMintMeta: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/primitives.h#L9
|
||||
*/
|
||||
struct CCSparkMintMeta {
|
||||
uint64_t height;
|
||||
const char* id;
|
||||
int isUsed;
|
||||
const char* txid;
|
||||
uint64_t i; // Diversifier.
|
||||
const unsigned char* d; // Encrypted diversifier.
|
||||
int dLength;
|
||||
uint64_t v; // Value.
|
||||
const unsigned char* k; // Nonce.
|
||||
int kLength;
|
||||
const char* memo;
|
||||
int memoLength;
|
||||
unsigned char* serial_context;
|
||||
int serial_contextLength;
|
||||
char type;
|
||||
CDataStream coin;
|
||||
|
||||
CCSparkMintMeta(uint64_t height, const char* id, int isUsed, const char* txid, uint64_t i, const unsigned char* d, int dLength, uint64_t v, const unsigned char* k, int kLength, const char* memo, int memoLength, unsigned char* serial_context, int serial_contextLength, char type, const CDataStream& coinData);
|
||||
~CCSparkMintMeta();
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::CoverSetData.
|
||||
*
|
||||
* CoverSetData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/spend_transaction.h#L28
|
||||
*/
|
||||
struct CCoverSetData {
|
||||
CDataStream** cover_set; // vs. struct CCoin* cover_set;
|
||||
int cover_setLength;
|
||||
const unsigned char* cover_set_representation;
|
||||
int cover_set_representationLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a std::unordered_map<uint64_t, spark::CoverSetData>.
|
||||
*
|
||||
* See https://github.com/firoorg/sparkmobile/blob/23099b0d9010a970ad75b9cfe05d568d634088f3/src/spark.cpp#L197
|
||||
*/
|
||||
struct CCoverSets {
|
||||
struct CCoverSetData* cover_sets;
|
||||
int cover_setsLength;
|
||||
};
|
||||
|
||||
struct OutputScript {
|
||||
unsigned char* bytes;
|
||||
int length;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for spark::createSparkSpendTransaction.
|
||||
|
||||
160
src/structs.h
Normal file
160
src/structs.h
Normal file
@@ -0,0 +1,160 @@
|
||||
#ifndef ORG_FIRO_SPARK_DART_STRUCTS_H
|
||||
#define ORG_FIRO_SPARK_DART_STRUCTS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "deps/sparkmobile/include/spark.h"
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::Coin.
|
||||
*
|
||||
* Coin: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/coin.h#L66
|
||||
*/
|
||||
struct CCoin {
|
||||
char type;
|
||||
const unsigned char* k;
|
||||
int kLength;
|
||||
const char* address;
|
||||
uint64_t v;
|
||||
const unsigned char* memo;
|
||||
int memoLength;
|
||||
const unsigned char* serial_context;
|
||||
int serial_contextLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::IdentifiedCoinData.
|
||||
*
|
||||
* IdentifiedCoinData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/coin.h#L19
|
||||
*/
|
||||
struct CIdentifiedCoinData {
|
||||
uint64_t i;
|
||||
const unsigned char* d;
|
||||
int dLength;
|
||||
uint64_t v;
|
||||
const unsigned char* k;
|
||||
int kLength;
|
||||
const char* memo;
|
||||
int memoLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::CRecipient.
|
||||
*
|
||||
* CRecipient: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/include/spark.h#L27
|
||||
*/
|
||||
struct CCRecipient {
|
||||
const unsigned char* pubKey;
|
||||
int pubKeyLength;
|
||||
uint64_t cAmount;
|
||||
int subtractFee;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::MintedCoinData.
|
||||
*
|
||||
* MintedCoinData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/mint_transaction.h#L12
|
||||
*/
|
||||
struct CMintedCoinData {
|
||||
const char* address;
|
||||
uint64_t value;
|
||||
const char* memo;
|
||||
};
|
||||
|
||||
struct PubKeyScript {
|
||||
unsigned char* bytes;
|
||||
int length;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a std::pair<CAmount, bool>.
|
||||
*
|
||||
* Note this is an ambiguation of a spark::CRecipient. This CRecip(ient) is just a wrapper for a
|
||||
* CAmount and bool pair, and is not the same as the spark::CRecipient struct above, which gets
|
||||
* wrapped for us as a CCRecipient and is unrelated to this struct.
|
||||
*
|
||||
* See https://github.com/firoorg/sparkmobile/blob/23099b0d9010a970ad75b9cfe05d568d634088f3/src/spark.cpp#L190
|
||||
*/
|
||||
struct CRecip {
|
||||
uint64_t amount;
|
||||
int subtractFee;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::OutputCoinData.
|
||||
*
|
||||
* OutputCoinData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/spend_transaction.h#L33
|
||||
*/
|
||||
struct COutputCoinData {
|
||||
const char* address;
|
||||
uint64_t value;
|
||||
const char* memo;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a <spark::OutputCoinData, bool>.
|
||||
*
|
||||
* See https://github.com/firoorg/sparkmobile/blob/23099b0d9010a970ad75b9cfe05d568d634088f3/src/spark.cpp#L195
|
||||
*/
|
||||
struct COutputRecipient {
|
||||
struct COutputCoinData output;
|
||||
int subtractFee;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::CSparkMintMeta.
|
||||
*
|
||||
* CSparkMintMeta: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/primitives.h#L9
|
||||
*/
|
||||
struct CCSparkMintMeta {
|
||||
uint64_t height;
|
||||
const char* id;
|
||||
int isUsed;
|
||||
const char* txid;
|
||||
uint64_t i; // Diversifier.
|
||||
const unsigned char* d; // Encrypted diversifier.
|
||||
int dLength;
|
||||
uint64_t v; // Value.
|
||||
const unsigned char* k; // Nonce.
|
||||
int kLength;
|
||||
const char* memo;
|
||||
int memoLength;
|
||||
unsigned char* serial_context;
|
||||
int serial_contextLength;
|
||||
char type;
|
||||
CDataStream coin;
|
||||
|
||||
CCSparkMintMeta(uint64_t height, const char* id, int isUsed, const char* txid, uint64_t i, const unsigned char* d, int dLength, uint64_t v, const unsigned char* k, int kLength, const char* memo, int memoLength, unsigned char* serial_context, int serial_contextLength, char type, const CDataStream& coinData);
|
||||
~CCSparkMintMeta();
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a spark::CoverSetData.
|
||||
*
|
||||
* CoverSetData: https://github.com/firoorg/sparkmobile/blob/8bf17cd3deba6c3b0d10e89282e02936d7e71cdd/src/spend_transaction.h#L28
|
||||
*/
|
||||
struct CCoverSetData {
|
||||
CDataStream** cover_set; // vs. struct CCoin* cover_set;
|
||||
int cover_setLength;
|
||||
const unsigned char* cover_set_representation;
|
||||
int cover_set_representationLength;
|
||||
};
|
||||
|
||||
/*
|
||||
* FFI-friendly wrapper for a std::unordered_map<uint64_t, spark::CoverSetData>.
|
||||
*
|
||||
* See https://github.com/firoorg/sparkmobile/blob/23099b0d9010a970ad75b9cfe05d568d634088f3/src/spark.cpp#L197
|
||||
*/
|
||||
struct CCoverSets {
|
||||
struct CCoverSetData* cover_sets;
|
||||
int cover_setsLength;
|
||||
};
|
||||
|
||||
struct OutputScript {
|
||||
unsigned char* bytes;
|
||||
int length;
|
||||
};
|
||||
|
||||
|
||||
#endif //ORG_FIRO_SPARK_DART_STRUCTS_H
|
||||
@@ -6,10 +6,10 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "flutter_libsparkmobile.h"
|
||||
#include "structs.h"
|
||||
#include "deps/sparkmobile/src/coin.h"
|
||||
#include "deps/sparkmobile/src/keys.h"
|
||||
#include "deps/sparkmobile//bitcoin/script.h" // For CScript.
|
||||
#include "deps/sparkmobile/bitcoin/script.h" // For CScript.
|
||||
|
||||
/*
|
||||
* Utility function to generate an address from keyData, index, and a diversifier.
|
||||
@@ -57,7 +57,7 @@ spark::SpendKey createSpendKeyFromData(const char *keyData, int index) {
|
||||
*
|
||||
* TODO manage the memory allocated by this function.
|
||||
*/
|
||||
struct CCoin createCCoin(char type, const unsigned char* k, int kLength, const char* address, uint64_t v, const unsigned char* memo, int memoLength, const unsigned char* serial_context, int serial_contextLength) {
|
||||
CCoin createCCoin(char type, const unsigned char* k, int kLength, const char* address, uint64_t v, const unsigned char* memo, int memoLength, const unsigned char* serial_context, int serial_contextLength) {
|
||||
CCoin coin;
|
||||
coin.type = type;
|
||||
coin.k = copyBytes(k, kLength);
|
||||
@@ -179,7 +179,7 @@ CRecipient fromFFI(const CCRecipient& c_struct) {
|
||||
*
|
||||
* TODO manage the memory allocated by this function.
|
||||
*/
|
||||
struct CCRecipient createCCRecipient(const unsigned char* pubKey, uint64_t amount, int subtractFee) {
|
||||
CCRecipient createCCRecipient(const unsigned char* pubKey, uint64_t amount, int subtractFee) {
|
||||
CCRecipient recipient;
|
||||
recipient.pubKey = copyBytes(pubKey, 32);
|
||||
recipient.cAmount = amount;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "flutter_libsparkmobile.h"
|
||||
#include "structs.h"
|
||||
#include "deps/sparkmobile/include/spark.h"
|
||||
#include "deps/sparkmobile/bitcoin/streams.h" // For CDataStream.
|
||||
|
||||
@@ -18,7 +18,7 @@ spark::Coin fromFFI(const CCoin& c_struct);
|
||||
|
||||
spark::Coin fromFFI(CDataStream& coinStream);
|
||||
|
||||
struct CCoin createCCoin(char type, const unsigned char* k, int kLength, const char* address, uint64_t v, const unsigned char* memo, int memoLength, const unsigned char* serial_context, int serial_contextLength);
|
||||
CCoin createCCoin(char type, const unsigned char* k, int kLength, const char* address, uint64_t v, const unsigned char* memo, int memoLength, const unsigned char* serial_context, int serial_contextLength);
|
||||
|
||||
CDataStream toFFI(const spark::Coin& cpp_struct);
|
||||
|
||||
@@ -34,7 +34,7 @@ CRecipient createCRecipient(const CScript& script, CAmount amount, bool subtract
|
||||
|
||||
CRecipient fromFFI(const CCRecipient& c_struct);
|
||||
|
||||
struct CCRecipient createCCRecipient(const unsigned char* pubKey, uint64_t amount, int subtractFee);
|
||||
CCRecipient createCCRecipient(const unsigned char* pubKey, uint64_t amount, int subtractFee);
|
||||
|
||||
CCRecipient toFFI(const CRecipient& cpp_struct);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user