mirror of
https://github.com/gosticks/iota.flash.js-java-wrapper.git
synced 2025-10-16 11:45:40 +00:00
Created IOTA Java wrapper for js lib
This commit is contained in:
commit
6ef4adbeb1
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.idea
|
||||
target
|
||||
7
LICENSE.md
Normal file
7
LICENSE.md
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright (c) 2017 Wlad Meixner.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
62
README.md
Normal file
62
README.md
Normal file
@ -0,0 +1,62 @@
|
||||
# IOTA Flash Channel Java Wrapper
|
||||
|
||||
This wrapper allows the usage of [iota.flash.js](https://github.com/iotaledger/iota.flash.js) lib directly in Java. This is achieved by running the iota.flash.js script and all dependencies (modified build of iota.flash.js) in the V8 engine (using [J2V8](https://github.com/eclipsesource/J2V8) bindings for V8).
|
||||
If you have any ideas please submit a request (I am totally not a Java guy so...)
|
||||
|
||||
|
||||
### iota.flash.js coverage
|
||||
|
||||
#### Multisig
|
||||
- [x] composeAddress
|
||||
- [x] updateLeafToRoot (needs testing)
|
||||
- [x] getDigest
|
||||
|
||||
#### Transfer
|
||||
- [x] prepare (needs testing)
|
||||
- [x] compose (needs testing)
|
||||
- [x] close (needs testing)
|
||||
- [ ] applyTransfers
|
||||
- [ ] appliedSignatures
|
||||
- [ ] getDiff
|
||||
- [ ] sign
|
||||
|
||||
### Installation
|
||||
|
||||
1. Clone repo
|
||||
2. Update maven ressources
|
||||
3. That's it.
|
||||
|
||||
### Updating iota.flash.js
|
||||
I will try to update the iota.flash.js as often as I can till it is automated.
|
||||
To manually update the lib do the following:
|
||||
|
||||
1. clone js lib from the repo `git clone git@github.com:iotaledger/iota.flash.js.git`
|
||||
2. inside the cloned project open the gulpfile.js and change dist task to this
|
||||
```javascript
|
||||
gulp.task('dist', () => {
|
||||
return gulp.src('lib/flash.js')
|
||||
.pipe(webpack({
|
||||
output: {
|
||||
filename: 'iota.flash.js',
|
||||
libraryTarget: 'umd',
|
||||
library: 'iotaFlash',
|
||||
umdNamedDefine: true
|
||||
}
|
||||
}))
|
||||
.pipe(gulp.dest(DEST))
|
||||
});
|
||||
```
|
||||
By doing this we get a umd package which we can access from the global js context under the name `iotaFlash
|
||||
3. Copy the file from `dist/iota.flash.js` of the js lib folder to this project under `res/iota.flash.js`
|
||||
4. Add `"use strict";`to the start of the file you just coppied (If you don't the V8 will complain).
|
||||
5. That was it...
|
||||
|
||||
### TODO
|
||||
|
||||
- [ ] write documentation
|
||||
- [ ] add some testing
|
||||
- [ ] add a way to update iota.flash.js from the repo without manual steps
|
||||
- [ ] cleanup maven
|
||||
- [ ] makte this project a easy to import lib
|
||||
|
||||
|
||||
16
iotaflashlibjswrapper.iml
Normal file
16
iotaflashlibjswrapper.iml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Maven: com.eclipsesource.j2v8:j2v8_macosx_x86_64:4.6.0" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
30
pom.xml
Normal file
30
pom.xml
Normal file
@ -0,0 +1,30 @@
|
||||
<?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>flashwifi</groupId>
|
||||
<artifactId>iota.flash.lib.js.wrapper</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.eclipsesource.j2v8</groupId>
|
||||
<artifactId>j2v8_macosx_x86_64</artifactId>
|
||||
<version>4.6.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!-- https://maven.apache.org/settings.html#Properties -->
|
||||
<properties>
|
||||
|
||||
<!-- <encoding>UTF-8</encoding> -->
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
</properties>
|
||||
</project>
|
||||
10554
res/iota.flash.js
Normal file
10554
res/iota.flash.js
Normal file
File diff suppressed because it is too large
Load Diff
24
src/main/java/Bundle.java
Normal file
24
src/main/java/Bundle.java
Normal file
@ -0,0 +1,24 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class Bundle {
|
||||
private ArrayList<Bundle> bundles;
|
||||
|
||||
public Bundle(ArrayList<Bundle> bundles) {
|
||||
this.bundles = bundles;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
List<Object> bundleList = new ArrayList<Object>();
|
||||
for (Bundle b: bundles) {
|
||||
bundleList.add(b.toMap());
|
||||
}
|
||||
map.put("bundles", bundleList);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
38
src/main/java/Digest.java
Normal file
38
src/main/java/Digest.java
Normal file
@ -0,0 +1,38 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class Digest {
|
||||
private int index;
|
||||
private int security;
|
||||
private String digest;
|
||||
|
||||
public Digest(String digest, int index, int security) {
|
||||
this.digest = digest;
|
||||
this.index = index;
|
||||
this.security = security;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public String getDigest() {
|
||||
return digest;
|
||||
}
|
||||
|
||||
public int getSecurity() {
|
||||
return security;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "{'digest':'"+ getDigest() + "', 'index':" + getIndex() + ", 'security':" + getSecurity() + "}";
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("index", getIndex());
|
||||
map.put("digest", getDigest());
|
||||
map.put("security", getSecurity());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
260
src/main/java/IotaFlashBridge.java
Normal file
260
src/main/java/IotaFlashBridge.java
Normal file
@ -0,0 +1,260 @@
|
||||
import com.eclipsesource.v8.*;
|
||||
import com.eclipsesource.v8.utils.V8ObjectUtils;
|
||||
import com.sun.org.apache.xpath.internal.operations.Mult;
|
||||
|
||||
import javax.jws.Oneway;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class IotaFlashBridge implements IotaFlashInterface {
|
||||
private String iotaLibPath;
|
||||
private V8 engine;
|
||||
private V8Object transfer;
|
||||
private V8Object multisig;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path
|
||||
* @throws IOException
|
||||
*/
|
||||
IotaFlashBridge(String path) throws IOException {
|
||||
this.iotaLibPath = path;
|
||||
|
||||
String file = readFile(path, Charset.defaultCharset());
|
||||
|
||||
this.engine = V8.createV8Runtime();
|
||||
// Eval lib into current v8 context.
|
||||
engine.executeVoidScript(file);
|
||||
multisig = (V8Object) engine.executeScript("iotaFlash.multisig");
|
||||
transfer = (V8Object) engine.executeScript("iotaFlash.transfer");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param digests
|
||||
* @return
|
||||
*/
|
||||
public MultisigAddress composeAddress(ArrayList<Digest> digests) {
|
||||
// Create js object for digest
|
||||
// TODO: find more clean way to do thi s.
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
for (Digest digest: digests) {
|
||||
list.add(digest.toMap());
|
||||
}
|
||||
V8Array digestsJS = V8ObjectUtils.toV8Array(engine, list);
|
||||
// Call js.
|
||||
List<Object> paramsList = new ArrayList<Object>();
|
||||
paramsList.add(digestsJS);
|
||||
V8Array params = V8ObjectUtils.toV8Array(engine, paramsList);
|
||||
|
||||
V8Object retV8 = multisig.executeObjectFunction("composeAddress", params);
|
||||
|
||||
// Parse return values from JS into Java world.
|
||||
Map<String, ? super Object> resultMap = V8ObjectUtils.toMap(retV8);
|
||||
// Parse result into Java Obj.
|
||||
String addr = (String) resultMap.get("address");
|
||||
int secSum = (Integer) resultMap.get("securitySum");
|
||||
MultisigAddress ret = new MultisigAddress(addr, secSum);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param seed
|
||||
* @param index
|
||||
* @param security
|
||||
* @return
|
||||
*/
|
||||
public Digest getDigest(String seed, int index, int security) {
|
||||
if (seed.length() < 81) {
|
||||
System.out.println("Seed is too short");
|
||||
return null;
|
||||
}
|
||||
V8Array params = new V8Array(engine);
|
||||
params.push(seed);
|
||||
params.push(index);
|
||||
params.push(security);
|
||||
V8Object ret = multisig.executeObjectFunction("getDigest", params);
|
||||
String dig = ret.getString("digest");
|
||||
int sec = ret.getInteger("security");
|
||||
int i = ret.getInteger("index");
|
||||
|
||||
return new Digest(dig, i, sec);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
*/
|
||||
public void updateLeafToRoot(MultisigAddress root) {
|
||||
Map<String, Object> map = root.toMap();
|
||||
// Create param list
|
||||
List<Object> paramsObj = new ArrayList<Object>();
|
||||
paramsObj.add(map);
|
||||
V8Array params = V8ObjectUtils.toV8Array(engine, paramsObj);
|
||||
|
||||
multisig.executeFunction("updateLeafToRoot", params);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param settlementAddresses Array of address of settlement wallet addresses
|
||||
* @param deposits array of deposits index of array is user id in flash channel
|
||||
* @param index index of the current flash channel user.
|
||||
* @param transfers array of all transfers (value, address) pairs
|
||||
* @return
|
||||
*/
|
||||
public Object prepare(ArrayList<String> settlementAddresses, ArrayList<Integer> deposits, int index, ArrayList<Transfer> transfers) {
|
||||
V8Array settlementAddressesJS = V8ObjectUtils.toV8Array(engine, settlementAddresses);
|
||||
V8Array depositJS = V8ObjectUtils.toV8Array(engine, deposits);
|
||||
List<Object> transferObj = new ArrayList<Object>();
|
||||
for (Transfer t: transfers) {
|
||||
transferObj.add(t.toMap());
|
||||
}
|
||||
V8Array transferJS = V8ObjectUtils.toV8Array(engine, transferObj);
|
||||
|
||||
// Now put all params into JS ready array.
|
||||
List<Object> params = new ArrayList<Object>();
|
||||
params.add(settlementAddressesJS);
|
||||
params.add(depositJS);
|
||||
params.add(index);
|
||||
params.add(transferJS);
|
||||
|
||||
// Call js function.
|
||||
V8Array ret = transfer.executeArrayFunction("prepare", V8ObjectUtils.toV8Array(engine, params));
|
||||
List<Object> transfersReturnJS = V8ObjectUtils.toList(ret);
|
||||
|
||||
// Call js.
|
||||
return transfersReturnJS;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param balance
|
||||
* @param deposits
|
||||
* @param outputs
|
||||
* @param multisig
|
||||
* @param remainderAddress
|
||||
* @param history
|
||||
* @param transfers
|
||||
* @param close
|
||||
* @return
|
||||
*/
|
||||
public List<Object> compose(int balance, ArrayList<Integer> deposits, ArrayList<Transfer> outputs, Object multisig, String remainderAddress, ArrayList<Bundle> history, ArrayList<Transfer> transfers, boolean close) {
|
||||
V8Array depositsJS = V8ObjectUtils.toV8Array(engine, deposits);
|
||||
// Outputs
|
||||
List<Object> outputsObj = new ArrayList<Object>();
|
||||
for (Transfer t: outputs) {
|
||||
outputsObj.add(t.toMap());
|
||||
}
|
||||
V8Array outputsJS = V8ObjectUtils.toV8Array(engine, outputsObj);
|
||||
|
||||
List<Object> transfersObj = new ArrayList<Object>();
|
||||
for (Transfer t: transfers) {
|
||||
transfersObj.add(t.toMap());
|
||||
}
|
||||
V8Array transfersJS = V8ObjectUtils.toV8Array(engine, transfersObj);
|
||||
|
||||
List<Object> trs = V8ObjectUtils.toList(transfersJS);
|
||||
|
||||
return trs;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param multisig
|
||||
* @param seed
|
||||
* @param bundles
|
||||
* @return
|
||||
*/
|
||||
public Object sign(Object multisig, String seed, ArrayList<Object> bundles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param bundles
|
||||
* @param signatures
|
||||
* @return
|
||||
*/
|
||||
public Object appliedSignatures(ArrayList<Object> bundles, ArrayList<Object> signatures) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
* @param remainder
|
||||
* @param history
|
||||
* @param bundles
|
||||
* @return
|
||||
*/
|
||||
public Object getDiff(ArrayList<Object> root, ArrayList<Object> remainder, ArrayList<Object> history, ArrayList<Object> bundles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param root
|
||||
* @param deposit
|
||||
* @param outputs
|
||||
* @param remainderAddress
|
||||
* @param transfers
|
||||
* @param signedBundles
|
||||
* @return
|
||||
*/
|
||||
public Object applayTransfers(Object root, Object deposit, Object outputs, Object remainderAddress, Object transfers, Object signedBundles) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param settlementAddresses
|
||||
* @param deposits
|
||||
* @return
|
||||
*/
|
||||
public Object close(ArrayList<String> settlementAddresses, ArrayList<Integer> deposits) {
|
||||
V8Array saJS = V8ObjectUtils.toV8Array(engine, settlementAddresses);
|
||||
// Deposits
|
||||
V8Array depositsJS = V8ObjectUtils.toV8Array(engine, deposits);
|
||||
|
||||
// Add to prams
|
||||
ArrayList<Object> paramsObj = new ArrayList<Object>();
|
||||
|
||||
paramsObj.add(saJS);
|
||||
paramsObj.add(depositsJS);
|
||||
V8Object res = transfer.executeObjectFunction("close", V8ObjectUtils.toV8Array(engine, paramsObj));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// Utils
|
||||
|
||||
/**
|
||||
*
|
||||
* @param path
|
||||
* @param encoding
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
static String readFile(String path, Charset encoding)
|
||||
throws IOException
|
||||
{
|
||||
byte[] encoded;
|
||||
try {
|
||||
encoded = Files.readAllBytes(Paths.get(path));
|
||||
} catch (IOException error) {
|
||||
System.out.println("Failed to load file: " + error.getLocalizedMessage());
|
||||
return "";
|
||||
}
|
||||
return new String(encoded, encoding);
|
||||
}
|
||||
}
|
||||
32
src/main/java/IotaFlashInterface.java
Normal file
32
src/main/java/IotaFlashInterface.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface IotaFlashInterface {
|
||||
// Multisig
|
||||
public MultisigAddress composeAddress(ArrayList<Digest> digests);
|
||||
|
||||
public void updateLeafToRoot(MultisigAddress root);
|
||||
|
||||
// Transfer
|
||||
public Object prepare(ArrayList<String> settlementAddresses, ArrayList<Integer> deposits, int index, ArrayList<Transfer> transfers);
|
||||
public List<Object> compose(int balance, ArrayList<Integer> deposits, ArrayList<Transfer> outputs, Object multisig, String remainderAddress, ArrayList<Bundle> history, ArrayList<Transfer> transfers, boolean close);
|
||||
|
||||
public Digest getDigest(String seed, int index, int security);
|
||||
|
||||
public Object sign(Object multisig, String seed, ArrayList<Object> bundles);
|
||||
public Object appliedSignatures(ArrayList<Object> bundles, ArrayList<Object> signatures);
|
||||
public Object getDiff(ArrayList<Object> root,
|
||||
ArrayList<Object> remainder,
|
||||
ArrayList<Object> history,
|
||||
ArrayList<Object> bundles);
|
||||
public Object applayTransfers(Object root,
|
||||
Object deposit,
|
||||
Object outputs,
|
||||
Object remainderAddress,
|
||||
Object transfers,
|
||||
Object signedBundles);
|
||||
public Object close(ArrayList<String> settlementAddresses, ArrayList<Integer> deposits);
|
||||
}
|
||||
|
||||
|
||||
|
||||
56
src/main/java/Main.java
Normal file
56
src/main/java/Main.java
Normal file
@ -0,0 +1,56 @@
|
||||
|
||||
import com.eclipsesource.v8.V8;
|
||||
import com.eclipsesource.v8.V8Object;
|
||||
import netscape.javascript.JSObject;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
System.out.println("IOTA Flash channel tester");
|
||||
|
||||
String pathToLib = "res/iota.flash.js";
|
||||
|
||||
System.out.println("Loading lib into V8 engine");
|
||||
IotaFlashInterface lib = new IotaFlashBridge(pathToLib);
|
||||
System.out.println("Lib imported");
|
||||
|
||||
|
||||
System.out.println("Testing getDigest(seed, index, security):");
|
||||
Digest digest1 = lib.getDigest("USERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSER", 0, 2);
|
||||
Digest digest2 = lib.getDigest("USERTWOUSERTWOUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSERONEUSER", 0, 2);
|
||||
System.out.println("Digest1: " + digest1.toString());
|
||||
|
||||
|
||||
System.out.println("Testing composeAddress(digests):");
|
||||
ArrayList<Digest> digests = new ArrayList<Digest>();
|
||||
digests.add(digest1);
|
||||
digests.add(digest2);
|
||||
MultisigAddress composedAddr = lib.composeAddress(digests);
|
||||
System.out.println("Got multisig addr for digests: " + composedAddr.getAddress() + ", securitySum: " + composedAddr.getSecuritySum());
|
||||
|
||||
testPrepare(lib);
|
||||
}
|
||||
|
||||
private static void testPrepare(IotaFlashInterface lib) {
|
||||
|
||||
System.out.println("Testing prepare()");
|
||||
ArrayList<String> settlementAddr = new ArrayList<String>();
|
||||
settlementAddr.add("RCZHCRDWMGJPHKROKEGVADVJXPGKEKNJRNLZZFPITUVEWNPGIWNUMKTYKMNB9DCNLWGMJZDNKYQDQKDLC");
|
||||
ArrayList<Integer> depositsPrep = new ArrayList<Integer>();
|
||||
ArrayList<Transfer> transfers = new ArrayList<Transfer>();
|
||||
|
||||
lib.prepare(settlementAddr, depositsPrep, 0, transfers);
|
||||
}
|
||||
}
|
||||
51
src/main/java/MultisigAddress.java
Normal file
51
src/main/java/MultisigAddress.java
Normal file
@ -0,0 +1,51 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
class MultisigAddress {
|
||||
private String address;
|
||||
private int securitySum;
|
||||
private ArrayList<MultisigAddress> children;
|
||||
private ArrayList<Bundle> bundles;
|
||||
|
||||
public MultisigAddress(String address, int securitySum) {
|
||||
this.address = address;
|
||||
this.securitySum = securitySum;
|
||||
this.children = new ArrayList<MultisigAddress>();
|
||||
this.bundles = new ArrayList<Bundle>();
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<MultisigAddress> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public int getSecuritySum() {
|
||||
return securitySum;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("address", getAddress());
|
||||
map.put("securitySum", getSecuritySum());
|
||||
|
||||
List<Object> childrenList = new ArrayList<Object>();
|
||||
for (MultisigAddress ma: children) {
|
||||
childrenList.add(ma.toMap());
|
||||
}
|
||||
map.put("children", childrenList);
|
||||
|
||||
List<Object> bundleList = new ArrayList<Object>();
|
||||
for (MultisigAddress ma: children) {
|
||||
bundleList.add(ma.toMap());
|
||||
}
|
||||
map.put("bundle", bundleList);
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
||||
75
src/main/java/Transaction.java
Normal file
75
src/main/java/Transaction.java
Normal file
@ -0,0 +1,75 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class Transaction {
|
||||
private String timestamp;
|
||||
private String address;
|
||||
private int value;
|
||||
private int obsoleteTag;
|
||||
private int tag;
|
||||
|
||||
// Signature stuff
|
||||
private String signatureMessageFragment = "";
|
||||
private String trunkTransaction = "";
|
||||
private String branchTransaction = "";
|
||||
|
||||
private String attachmentTimestamp = "";
|
||||
private String attachmentTimestampUpperBound = "";
|
||||
private String attachmentTimestampLowerBound = "";
|
||||
|
||||
private String nonce = "";
|
||||
|
||||
// Unsigned constructor
|
||||
public Transaction(String address, int value, int obsoleteTag, int tag, String timestamp) {
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
this.obsoleteTag = obsoleteTag;
|
||||
this.tag = tag;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
// Signed constructor
|
||||
public Transaction(String address,
|
||||
int value,
|
||||
int obsoleteTag,
|
||||
int tag,
|
||||
String timestamp,
|
||||
String signatureMessageFragment,
|
||||
String trunkTransaction,
|
||||
String branchTransaction,
|
||||
|
||||
String attachmentTimestamp,
|
||||
String attachmentTimestampUpperBound,
|
||||
String attachmentTimestampLowerBound
|
||||
) {
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
this.obsoleteTag = obsoleteTag;
|
||||
this.tag = tag;
|
||||
this.timestamp = timestamp;
|
||||
this.signatureMessageFragment = signatureMessageFragment;
|
||||
this.trunkTransaction = trunkTransaction;
|
||||
this.branchTransaction = branchTransaction;
|
||||
|
||||
this.attachmentTimestamp = attachmentTimestamp;
|
||||
this.attachmentTimestampUpperBound = attachmentTimestampUpperBound;
|
||||
this.attachmentTimestampLowerBound = attachmentTimestampLowerBound;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("address", address);
|
||||
map.put("value", value);
|
||||
map.put("obsoleteTag", obsoleteTag);
|
||||
map.put("tag", tag);
|
||||
map.put("timestamp", timestamp);
|
||||
return map;
|
||||
}
|
||||
}
|
||||
32
src/main/java/Transfer.java
Normal file
32
src/main/java/Transfer.java
Normal file
@ -0,0 +1,32 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class Transfer {
|
||||
private String address;
|
||||
private int value;
|
||||
|
||||
public Transfer(String address, int value) {
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{'address':'" + getAddress() + "','value':" + getValue() +" }";
|
||||
}
|
||||
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("address", getAddress());
|
||||
map.put("value", getValue());
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user