This commit is contained in:
Hanh 2022-10-19 11:57:13 +08:00
parent 36e654c131
commit 49eeb7bd54
8 changed files with 793 additions and 0 deletions

View File

@ -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

View File

@ -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;

80
integrations/java/pom.xml Normal file
View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>app.ywallet</groupId>
<artifactId>java</artifactId>
<version>1.0-SNAPSHOT</version>
<name>java</name>
<!-- FIXME change it to the project's website -->
<url>https://ywallet.app</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.7.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -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

View File

@ -0,0 +1,14 @@
#include <jni.h>
#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;
}

View File

@ -0,0 +1,21 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* 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

View File

@ -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();
}

629
openapi.yml Normal file
View File

@ -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