From 49eeb7bd542e2d444756aad5618c46fe72559383 Mon Sep 17 00:00:00 2001 From: Hanh Date: Wed, 19 Oct 2022 11:57:13 +0800 Subject: [PATCH] API Doc --- binding.h | 2 + binding2.h | 2 + integrations/java/pom.xml | 80 +++ integrations/java/src/main/cpp/Makefile | 7 + .../java/src/main/cpp/app_ywallet_App.cpp | 14 + .../java/src/main/cpp/app_ywallet_App.h | 21 + .../java/src/main/java/app/ywallet/App.java | 38 ++ openapi.yml | 629 ++++++++++++++++++ 8 files changed, 793 insertions(+) create mode 100644 integrations/java/pom.xml create mode 100644 integrations/java/src/main/cpp/Makefile create mode 100644 integrations/java/src/main/cpp/app_ywallet_App.cpp create mode 100644 integrations/java/src/main/cpp/app_ywallet_App.h create mode 100644 integrations/java/src/main/java/app/ywallet/App.java create mode 100644 openapi.yml diff --git a/binding.h b/binding.h index 292267f..993d443 100644 --- a/binding.h +++ b/binding.h @@ -7,8 +7,10 @@ typedef long long int uint64_t; typedef long long int uintptr_t; typedef long int int32_t; typedef long int uint32_t; +#ifndef __cplusplus typedef char bool; #endif +#endif typedef void *DartPostCObjectFnType; #define QR_DATA_SIZE 256 diff --git a/binding2.h b/binding2.h index 51d8733..c45ce88 100644 --- a/binding2.h +++ b/binding2.h @@ -7,6 +7,8 @@ typedef long long int uint64_t; typedef long long int uintptr_t; typedef long int int32_t; typedef long int uint32_t; +#ifndef __cplusplus typedef char bool; #endif +#endif typedef void *DartPostCObjectFnType; diff --git a/integrations/java/pom.xml b/integrations/java/pom.xml new file mode 100644 index 0000000..ca46c85 --- /dev/null +++ b/integrations/java/pom.xml @@ -0,0 +1,80 @@ + + + + 4.0.0 + + app.ywallet + java + 1.0-SNAPSHOT + + java + + https://ywallet.app + + + UTF-8 + 1.7 + 1.7 + + + + + org.xerial + sqlite-jdbc + 3.7.2 + + + junit + junit + 4.11 + test + + + + + + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-jar-plugin + 3.0.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + maven-site-plugin + 3.7.1 + + + maven-project-info-reports-plugin + 3.0.0 + + + + + diff --git a/integrations/java/src/main/cpp/Makefile b/integrations/java/src/main/cpp/Makefile new file mode 100644 index 0000000..5c0adcb --- /dev/null +++ b/integrations/java/src/main/cpp/Makefile @@ -0,0 +1,7 @@ +libjava_warp.so: + +app_ywallet_App.o: app_ywallet_App.cpp + g++ -c -fPIC -I${JAVA_HOME}/include -I${JAVA_HOME}/include/linux app_ywallet_App.cpp + +libjava_warp.so: app_ywallet_App.o + g++ -shared -fPIC -o libjava_warp.so app_ywallet_App.o -L/usr/lib -lwarp_api_ffi diff --git a/integrations/java/src/main/cpp/app_ywallet_App.cpp b/integrations/java/src/main/cpp/app_ywallet_App.cpp new file mode 100644 index 0000000..a76d1f4 --- /dev/null +++ b/integrations/java/src/main/cpp/app_ywallet_App.cpp @@ -0,0 +1,14 @@ +#include +#include "app_ywallet_App.h" + +extern "C" { + #include "../../../../../binding.h" +} + +JNIEXPORT jint JNICALL Java_app_ywallet_App_newAccount + (JNIEnv *, jobject) { + init_wallet((char *)"."); + CResult_u32 result = new_account(0, (char *)"test", (char*)"", 0); + return result.value; +} + diff --git a/integrations/java/src/main/cpp/app_ywallet_App.h b/integrations/java/src/main/cpp/app_ywallet_App.h new file mode 100644 index 0000000..bde2cd3 --- /dev/null +++ b/integrations/java/src/main/cpp/app_ywallet_App.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class app_ywallet_App */ + +#ifndef _Included_app_ywallet_App +#define _Included_app_ywallet_App +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: app_ywallet_App + * Method: newAccount + * Signature: ()Lapp/ywallet/ResultInt; + */ +JNIEXPORT jint JNICALL Java_app_ywallet_App_newAccount + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/integrations/java/src/main/java/app/ywallet/App.java b/integrations/java/src/main/java/app/ywallet/App.java new file mode 100644 index 0000000..d68d9a4 --- /dev/null +++ b/integrations/java/src/main/java/app/ywallet/App.java @@ -0,0 +1,38 @@ +package app.ywallet; + +import java.sql.*; + +/** + */ +public class App +{ + static { + System.loadLibrary("java_warp"); + } + + public static void main( String[] args ) throws Exception + { + Class.forName("org.sqlite.JDBC"); + final App app = new App(); + + // Create a new account + final int id = app.newAccount(); + + // Connect to the database via JDBC + Connection conn = DriverManager.getConnection("jdbc:sqlite:zec.db"); + + // Query the seed and address of the account by id + String query = "SELECT seed, address FROM accounts WHERE id_account = ?"; + PreparedStatement statement = conn.prepareStatement(query); + statement.setInt(1, id); + ResultSet rs = statement.executeQuery(); + while (rs.next()) { + String seed = rs.getString(1); + String address = rs.getString(2); + + System.out.println("seed phrase: " + seed + ", address: " + address); + } + } + + private native int newAccount(); +} diff --git a/openapi.yml b/openapi.yml new file mode 100644 index 0000000..631550a --- /dev/null +++ b/openapi.yml @@ -0,0 +1,629 @@ +openapi: 3.0.0 +info: + title: Warp Sync API + version: 1.2.15 + description: |- + This is the fast synchronization, multi account and multi currency + wallet for Ycash and Zcash. + contact: + name: Hanh Huynh Huu + url: "https://ywallet.app" +tags: + - name: config + description: |- + Set the current account. Account methods use the current account. + - Zcash: coin = 0 + - Ycash: coin = 1 + - name: sync + description: Blockchain Synchronization + - name: account + description: Account Management + - name: payment_uri + description: Payment URI + +paths: + /set_active: + post: + tags: [ config ] + operationId: set_active + description: set the current account for a given coin + parameters: + - name: coin + in: query + required: true + schema: + type: integer + format: uint8 + minimum: 0 + - name: id_account + in: query + required: true + schema: + type: integer + format: uint32 + minimum: 1 + responses: + '200': + description: '' + /new_account: + post: + tags: [ account ] + operationId: new_account + description: create a new account from a given seed/secret key/viewing key + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/AccountSeed' + required: true + responses: + '200': + description: 'account id' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /accounts: + get: + operationId: list_accounts + tags: [ account ] + description: get a list of all accounts + responses: + '200': + description: '' + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/AccountRec' + '500': + description: 'error message' + /sync: + post: + operationId: sync + tags: [ sync ] + description: Synchronizes with the tip of the blockchain + parameters: + - name: offset + in: query + description: |- + Number of blocks to synchronize from the tip of the blockchain. + For example: + - If 0, sync catches up with the latest block + - If 1, sync synchronizes up to the latest block height - 1 + + Creates a new checkpoint + schema: + type: integer + format: uint32 + minimum: 0 + nullable: true + responses: + '200': + description: '' + '500': + description: 'error message' + /rewind: + post: + operationId: rewind + tags: [ sync ] + description: Rewind the blockchain to a previous height + parameters: + - name: height + in: query + description: |- + Requested height to rewind to. Note that this will be rounded + to the nearest checkpoint before this height. + required: true + schema: + type: integer + format: uint32 + minimum: 0 + responses: + '200': + description: '' + '500': + description: 'error message' + /latest_height: + get: + operationId: get_latest_height + tags: [ sync ] + description: Latest block height and current synced height + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/Heights' + '500': + description: 'error message' + /backup: + get: + operationId: get_backup + tags: [ account ] + description: |- + Get the account information needed to make a backup. + The `allow_backup` option must be set in the config file + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/Backup' + '500': + description: 'error message' + /balance: + get: + operationId: get_balance + tags: [ account ] + description: Get the account balance in zats + responses: + '200': + description: 'zats' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /address: + get: + operationId: get_address + tags: [ account ] + description: Get the account address (z-addr) + responses: + '200': + description: 'zaddr' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /tx_history: + get: + operationId: get_tx_history + tags: [ account ] + description: Get the account history + responses: + '200': + description: 'transactions' + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/TxRec' + '500': + description: 'error message' + /pay: + post: + operationId: pay + tags: [ account ] + description: Make a payment. The `allow_send` flag must be set in the config file + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Payment' + required: true + responses: + '200': + description: '' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /mark_synced: + post: + operationId: mark_synced + tags: [ sync ] + description: |- + Create a checkpoint at the current latest height without actually + doing any synchronization work. Only use it if you have a new account + and you are sure there are no prior transactions. + responses: + '200': + description: '' + '500': + description: 'error message' + /create_offline_tx: + post: + operationId: create_offline_tx + tags: [ account ] + description: Create a transaction for offline signing + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Payment' + required: true + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/Tx' + '500': + description: 'error message' + /sign_offline_tx: + post: + operationId: sign_offline_tx + tags: [ account ] + description: |- + Sign an offline transaction. Tx object must be created by calling + `create_offline_tx` and the secret key must be available in the current + account + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Tx' + required: true + responses: + '200': + description: 'signed raw transaction' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /broadcast_tx: + post: + operationId: broadcast_tx + tags: [ account ] + parameters: + - name: tx_hex + in: query + required: true + description: 'signed raw transaction' + schema: + type: string + responses: + '200': + description: 'txid' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /new_diversified_address: + get: + operationId: new_diversified_address + tags: [ account ] + description: get a new diversified address + responses: + '200': + description: 'diversified address' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /make_payment_uri: + post: + operationId: make_payment_uri + tags: [ payment_uri ] + description: create a payment uri + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/PaymentURI' + required: true + responses: + '200': + description: 'payment uri' + content: + text/plain: + schema: + type: string + '500': + description: 'error message' + /parse_payment_uri: + get: + operationId: parse_payment_uri + tags: [ payment_uri ] + description: decode a payment uri + parameters: + - name: uri + in: query + description: 'payment uri' + required: true + schema: + type: string + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/PaymentURI' + '500': + description: 'error message' +components: + schemas: + AccountSeed: + type: object + required: + - coin + - name + properties: + coin: + type: integer + format: uint8 + minimum: 0 + description: |- + - 0 for zcash, + - 1 for ycash + name: + type: string + description: account name + key: + type: string + nullable: true + description: |- + seed phrase, secret key or viewing key. null for a new account + from a random seed phrase. + index: + type: integer + format: uint32 + minimum: 0 + nullable: true + description: |- + if key is a seed phrase, this is the index of the sub account. + 0 by default + AccountRec: + type: object + required: + - address + - id_account + - name + properties: + id_account: + type: integer + format: uint32 + minimum: 1 + description: account id + name: + type: string + description: account name + address: + type: string + description: z-address + Heights: + type: object + required: + - latest + - synced + properties: + latest: + description: Latest block height + type: integer + format: uint32 + minimum: 0 + synced: + description: Latest checkpoint height + type: integer + format: uint32 + minimum: 0 + Backup: + type: object + required: + - fvk + properties: + seed: + type: string + nullable: true + description: Seed phrase + sk: + type: string + nullable: true + description: Secret key + fvk: + type: string + description: Full viewing key + TxRec: + type: object + required: + - address + - height + - memo + - timestamp + - txid + - value + properties: + txid: + type: string + description: transaction id + height: + type: integer + format: uint32 + minimum: 0 + description: block height + timestamp: + type: integer + format: uint32 + minimum: 0 + description: timestamp in secs since epoch + value: + type: integer + format: int64 + description: value in zats + address: + type: string + description: zaddr + memo: + type: string + description: memo text + Payment: + type: object + required: + - confirmations + - recipients + properties: + recipients: + type: array + items: + $ref: '#/components/schemas/Recipient' + confirmations: + type: integer + format: uint32 + minimum: 0 + description: number of confirmations required for a note to be eligible for spending + Recipient: + type: object + required: + - address + - amount + - max_amount_per_note + - memo + - reply_to + - subject + properties: + address: + type: string + description: destination z-addr + amount: + type: integer + format: uint64 + minimum: 0 + description: amount in zats + reply_to: + type: boolean + description: if true, include sender addr in memo + subject: + type: string + description: subject included in the memo + memo: + type: string + description: memo text + max_amount_per_note: + type: integer + format: uint64 + minimum: 0 + description: split note if it exceeds this amount + Tx: + type: object + required: + - change + - height + - inputs + - outputs + - ovk + - t_inputs + properties: + height: + type: integer + format: uint32 + minimum: 0 + description: tx height + t_inputs: + description: transparent inputs + type: array + items: + $ref: '#/components/schemas/TTxIn' + inputs: + description: shielded inputs + type: array + items: + $ref: '#/components/schemas/TxIn' + outputs: + description: outputs + type: array + items: + $ref: '#/components/schemas/TxOut' + change: + description: change addr + type: string + ovk: + description: outgoing viewing key + type: string + TTxIn: + type: object + required: + - amount + - 'n' + - op + - script + properties: + op: + type: string + 'n': + type: integer + format: uint32 + minimum: 0 + amount: + type: integer + format: uint64 + minimum: 0 + script: + type: string + TxIn: + type: object + required: + - amount + - diversifier + - fvk + - rseed + - witness + properties: + diversifier: + type: string + fvk: + type: string + amount: + type: integer + format: uint64 + minimum: 0 + rseed: + type: string + witness: + type: string + TxOut: + type: object + required: + - addr + - amount + - memo + - ovk + properties: + addr: + type: string + amount: + type: integer + format: uint64 + minimum: 0 + ovk: + type: string + memo: + type: string + PaymentURI: + type: object + required: + - address + - amount + - memo + properties: + address: + description: recipient address (taddr or zaddr) + type: string + amount: + description: amount in zats + type: integer + format: uint64 + minimum: 0 + memo: + description: memo text + type: string