|
15 | 15 | import org.web3j.protocol.Web3j; |
16 | 16 | import org.web3j.protocol.core.methods.response.TransactionReceipt; |
17 | 17 | import org.web3j.protocol.http.HttpService; |
18 | | -import org.web3j.sample.contracts.generated.Greeter; |
19 | 18 | import org.web3j.tx.Transfer; |
20 | 19 | import org.web3j.tx.gas.ContractGasProvider; |
21 | 20 | import org.web3j.tx.gas.DefaultGasProvider; |
22 | 21 | import org.web3j.utils.Convert; |
23 | 22 | import org.web3j.utils.Numeric; |
24 | 23 |
|
| 24 | +// TODO: Remove this! |
| 25 | +import android.util.Log; |
| 26 | + |
25 | 27 | // Heavily influenced by (thanks guys!): |
26 | 28 | // https://github.com/web3j/sample-project-gradle/blob/master/src/main/java/org/web3j/sample/Application.java |
27 | 29 | public final class Web3Module extends ReactContextBaseJavaModule { |
28 | 30 |
|
| 31 | + /* Static Declarations */ |
| 32 | + public static final String TAG = "Web3Module"; |
| 33 | + |
| 34 | + /** A simple utility method to print via ADB. */ |
| 35 | + private static final void debug(final String pString) { |
| 36 | + Log.d(TAG, pString); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
29 | 40 | /* Member Variables. */ |
30 | 41 | private final ReactApplicationContext mReactApplicationContext; |
31 | | - private Web3j mWeb3j; |
32 | | - private Credentials mCredentials; |
| 42 | + //private Web3j mWeb3j; |
| 43 | + //private Credentials mCredentials; |
33 | 44 |
|
34 | 45 | /** Constructor */ |
35 | 46 | public Web3Module(final ReactApplicationContext pReactApplicationContext) { |
36 | 47 | super(pReactApplicationContext); |
37 | 48 | // Initialize Member Variables. |
38 | 49 | this.mReactApplicationContext = pReactApplicationContext; |
39 | | - this.mWeb3j = null; |
40 | | - this.mCredentials = null; |
| 50 | + //this.mWeb3j = null; |
| 51 | + //this.mCredentials = null; |
41 | 52 | } |
42 | 53 |
|
43 | | - @Override |
44 | | - public String getName() { |
45 | | - return "Web3"; |
46 | | - } |
| 54 | + /** Module name when imported via NativeModules. **/ |
| 55 | + @Override public String getName() { return "Web3"; } |
47 | 56 |
|
48 | | - // XXX: Where to get wallet? Where to get password? |
49 | 57 | @ReactMethod |
50 | | - public final void create(final String pService, final String pPassword, final Promise pPromise) { |
51 | | - // Ensure we're being passed a valid service, such as "https://rinkeby.infura.io/<your token>" |
52 | | - if (pService != null && pService.length > 0) { |
53 | | - this.setWeb3j(Web3j.build(new HttpService(pService))); |
54 | | - // TODO: How to pass a wallet buffer? Where to get a wallet from? Anyone?! |
55 | | - this.setCredentials(WalletUtils.loadCredentials(pPassword, "/path/to/<walletfile>")); |
56 | | - // TODO: Can we return interesting properties, like the address of the wallet? |
57 | | - pPromise.resolve(Arguments.createMap()); |
58 | | - } else { |
59 | | - pPromise.reject(new Exception("Calls to create() expect a non-null, non empty service name.")); |
60 | | - } |
| 58 | + public final void init(final ReadableMap pKeystore, final String pPassword, final Promise pPromise) { |
| 59 | + debug("got to this bit"); |
| 60 | + debug(pKeystore.toString()); |
| 61 | + debug(pPassword); |
| 62 | + pPromise.resolve(Arguments.createMap()); |
61 | 63 | } |
62 | 64 |
|
63 | | - // TODO: Validate parameters. |
64 | | - @ReactMethod |
65 | | - public final void sendFunds(final String pAddress, final String pAmount, final String pUnits, final Promise pPromise) { |
66 | | - try { |
67 | | - this.throwIfMissingDependencies(); |
68 | | - // TODO: Verify this transaction value propagates through. |
69 | | - final Transaction t = Transfer.sendFunds(this.getWeb3j(), this.getCredentials(), pAddress, new BigDecimal(pAmount), Convert.Unit.valueOf(pUnits)); |
70 | | - // TODO: Propagate useful information. |
71 | | - // final String transactionHash = t.getTransactionHash(); |
72 | | - pPromise.resolve(Arguments.createMap()); |
73 | | - } catch (final Exception pException) { |
74 | | - pPromise.reject(pException); |
75 | | - } |
76 | | - } |
| 65 | + //// XXX: Where to get wallet? Where to get password? |
| 66 | + //@ReactMethod |
| 67 | + //public final void create(final String pService, final String pPassword, final Promise pPromise) { |
| 68 | + // // Ensure we're being passed a valid service, such as "https://rinkeby.infura.io/<your token>" |
| 69 | + // if (pService != null && pService.length > 0) { |
| 70 | + // this.setWeb3j(Web3j.build(new HttpService(pService))); |
| 71 | + // // TODO: How to pass a wallet buffer? Where to get a wallet from? Anyone?! |
| 72 | + // this.setCredentials(WalletUtils.loadCredentials(pPassword, "/path/to/<walletfile>")); |
| 73 | + // // TODO: Can we return interesting properties, like the address of the wallet? |
| 74 | + // pPromise.resolve(Arguments.createMap()); |
| 75 | + // } else { |
| 76 | + // pPromise.reject(new Exception("Calls to create() expect a non-null, non empty service name.")); |
| 77 | + // } |
| 78 | + //} |
77 | 79 |
|
78 | | - @ReactMethod |
79 | | - public final void destroy(final Promise pPromise) { |
80 | | - try { |
81 | | - this.throwIfMissingDependencies(); |
82 | | - this.setWeb3j(null); |
83 | | - this.setCredentials(null); |
84 | | - pPromise.resolve(Arguments.createMap()); |
85 | | - } catch (final Exception pException) { |
86 | | - pPromise.reject(pException); |
87 | | - } |
88 | | - } |
| 80 | + //// TODO: Validate parameters. |
| 81 | + //@ReactMethod |
| 82 | + //public final void sendFunds(final String pAddress, final String pAmount, final String pUnits, final Promise pPromise) { |
| 83 | + // try { |
| 84 | + // this.throwIfMissingDependencies(); |
| 85 | + // // TODO: Verify this transaction value propagates through. |
| 86 | + // final Transaction t = Transfer.sendFunds(this.getWeb3j(), this.getCredentials(), pAddress, new BigDecimal(pAmount), Convert.Unit.valueOf(pUnits)); |
| 87 | + // // TODO: Propagate useful information. |
| 88 | + // // final String transactionHash = t.getTransactionHash(); |
| 89 | + // pPromise.resolve(Arguments.createMap()); |
| 90 | + // } catch (final Exception pException) { |
| 91 | + // pPromise.reject(pException); |
| 92 | + // } |
| 93 | + //} |
89 | 94 |
|
90 | | - /** Throws an Exception if the Service has not been configured. */ |
91 | | - private final void throwIfMissingDependencies() { |
92 | | - if (this.getWeb3j() == null || this.getCredentials() == null) { |
93 | | - throw new IllegalStateException("You must call create() before attempting to interact with a service."); |
94 | | - } |
95 | | - } |
| 95 | + //@ReactMethod |
| 96 | + //public final void destroy(final Promise pPromise) { |
| 97 | + // try { |
| 98 | + // this.throwIfMissingDependencies(); |
| 99 | + // this.setWeb3j(null); |
| 100 | + // this.setCredentials(null); |
| 101 | + // pPromise.resolve(Arguments.createMap()); |
| 102 | + // } catch (final Exception pException) { |
| 103 | + // pPromise.reject(pException); |
| 104 | + // } |
| 105 | + //} |
96 | 106 |
|
97 | | - /* Getters and Setters */ |
98 | | - private final void setWeb3j(final Web3j pWeb3j) { |
99 | | - this.mWeb3j = pWeb3j; |
100 | | - } |
| 107 | + ///** Throws an Exception if the Service has not been configured. */ |
| 108 | + //private final void throwIfMissingDependencies() { |
| 109 | + // if (this.getWeb3j() == null || this.getCredentials() == null) { |
| 110 | + // throw new IllegalStateException("You must call create() before attempting to interact with a service."); |
| 111 | + // } |
| 112 | + //} |
101 | 113 |
|
102 | | - private final Web3j getWeb3j() { |
103 | | - return this.mWeb3j; |
104 | | - } |
| 114 | + ///* Getters and Setters */ |
| 115 | + //private final void setWeb3j(final Web3j pWeb3j) { |
| 116 | + // this.mWeb3j = pWeb3j; |
| 117 | + //} |
105 | 118 |
|
106 | | - private final void setCredentials(final Credentials pCredentials) { |
107 | | - this.mCredentials = pCredentials; |
108 | | - } |
| 119 | + //private final Web3j getWeb3j() { |
| 120 | + // return this.mWeb3j; |
| 121 | + //} |
109 | 122 |
|
110 | | - private final Credentials getCredentials() { |
111 | | - return this.mCredentials; |
112 | | - } |
| 123 | + //private final void setCredentials(final Credentials pCredentials) { |
| 124 | + // this.mCredentials = pCredentials; |
| 125 | + //} |
| 126 | + |
| 127 | + //private final Credentials getCredentials() { |
| 128 | + // return this.mCredentials; |
| 129 | + //} |
113 | 130 |
|
114 | 131 | //@ReactMethod |
115 | 132 | //public void sampleMethod(String stringArgument, int numberArgument, Callback callback) { |
|
0 commit comments