adridadou / eth-contract-api Goto Github PK
View Code? Open in Web Editor NEWEthereumJ native API or how to call contracts easily and with type safety
Home Page: http://www.davidroon.com/ethcontractapi/
License: Apache License 2.0
EthereumJ native API or how to call contracts easily and with type safety
Home Page: http://www.davidroon.com/ethcontractapi/
License: Apache License 2.0
if a transaction is never added because of a lack of fund, it should raise an exception
The idea is the following:
This way, we can have an instant bootstrap but with a switch to a local node as soon as possible.
This can be great to start a client without having to wait
it should be possible to map the same contract twice with the same name
When we create a Proxy instance, the types in solidity and the interface should be checked to make sure there is no mismatch.
Missing a method should not create an error but maybe a warning
It should be possible to get future value back when you call a smart contract method that creates a transaction.
This means the limitation that tx calls should return nothing (void) needs to be lifted
consider RxJava to implement that
https://github.com/ReactiveX/RxJava
We should get an EthereumApiException if the smart contract throws
It should be possible to have a listener to a specific address and get notified when a transaction involves this address
Sometimes the code is not available but the ABI is.
It should be possible to map with the ABI only, not the source
It should be possible to create custom conversions for input / output values
Right now the checks done are:
The missing checks are:
The tricky part here is to check that exists a conversion path between both that makes it compatible or not.
It would be actually pretty cool to be able to give the method of a proxied contract as a parameter.
https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
https://solidity.readthedocs.io/en/develop/types.html#function-types
After playing around a bit, nice work btw. thanks for it, I notice than currently only functions are supported, do you plan to add attributes and events as well ?
May be I have overlooked it.
eth-contract-api\src\test\java\org\adridadou\TestnetConnectionTest.java
@test
public void run() throws Exception {
run(testnet, "cow", "");
}
-------log---------
18:10:08.337 INFO [sync] Peer 8246787f: header sync completed, [2] headers in queue
18:10:09.135 INFO [blockqueue] No parent on the chain for block.number: 1385072 block.hash: 8e5ba0
18:10:14.172 ERROR [blockqueue] Error processing block #1385071 (b80755 <~ a37b08) Txs:1, Unc: 0:
java.lang.NullPointerException
at org.ethereum.trie.TrieImpl.delete(TrieImpl.java:286)
at org.ethereum.trie.TrieImpl.insertOrDelete(TrieImpl.java:203)
at org.ethereum.trie.TrieImpl.update(TrieImpl.java:133)
at org.ethereum.trie.SecureTrie.update(SecureTrie.java:25)
at org.ethereum.trie.SecureTrie.delete(SecureTrie.java:30)
at org.ethereum.db.ContractDetailsImpl.put(ContractDetailsImpl.java:60)
at org.ethereum.db.ContractDetailsCacheImpl.commit(ContractDetailsCacheImpl.java:163)
at org.ethereum.db.RepositoryTrack.commit(RepositoryTrack.java:308)
at org.ethereum.core.BlockchainImpl.applyBlock(BlockchainImpl.java:744)
Needs a way to send value while calling a smart contract or simply sending value
According to the description in the wiki void-typed methods are considered as requiring a transaction.
I believe it's not a good idea to ignore the result of a transaction since semantically void
means work has been done
. If a user needs such a behavior, they can make the method return CompletableFuture<Void>
and not to wait for the completion intentionally.
Here is a tiny PR addressing the issue #47
It would be nice to have a possibility to check the validness of the address using Facade something similar to:
ethereum.getRepository().isExist()
it should be part of the API to check the balance of an address.
the function signature should be:
EthValue checkBalance(EthAddress address);
Where EthValue is a type to handle ETH. You should be able to get the value in any unit, wei, eth, finney etc ..
For contract proxy, it would be nice to be able to use RPC instead of the full EthereumJ
It should be possible to create a new contract and pass parameters to its constructor
an address is converted into EthAddress when it is defined as a return value, it should be possible to have it as a parameter too
Right now conversion is being done for return values from functions.
The same should be done for input parameters
Right now, I have copied some of the code in EthereumJ to make it possible to call smart contracts.
The issue is that I don't own this code meaning I don't have proper tests for it and it is harder to make changes or improvements.
It should be possible to add value to a call when I call a "payable" function
In case a contract method return type is 'void' the transaction doesn't get sent.
Right now, you have to wait for the blockchain to be in sync to make it work.
It would be good to make it possible to work in a non blocking way, i.e. working with the contracts before it is in sync, at least for the constant calls
right now, we get a version 0.3.x of solc from ethereumJ
we should change that so we can update the version
RIght now, keystore works only for OSX
Needs to detect if the lib runs on windows and make it work for it
It would be great to make method
BigInteger getNonce(final EthAccount account)
available in EthereumFacade.
Instead of having a static json file, we need a class to help configure this.
This way it will be:
Mapping different result types to java types
Integer,
Long,
String,
Boolean,
Address
It should be possible to create multiple proxy objects for the same smart contract but different accounts without rechecking everything everytime
Today, a function can return more than one value, each with a type and a name.
The idea would be to be able to map a class to this set of values
Right now, you need to copy paste the EthereumFacadeProvider for main net or morden to make it for your private network. It should be much easier
It should be possible to listen to events and react to them
You can find the documentation of how import works here : http://solidity.readthedocs.io/en/develop/layout-of-source-files.html
The idea would be to simulate the import by replacing it with the actual code. Because the import logic is fairly complex, this story will be split into multiple sub issues for each import feature. The first one being to simply import a file as is.
java.io.FileNotFoundException: C:\Users\pc\Library\Ethereum\keystore\cow (系统找不到指定的路径。)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at org.codehaus.jackson.JsonFactory.createJsonParser(JsonFactory.java:504)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1817)
at org.adridadou.ethereum.keystore.Keystore.fromKeystore(Keystore.java:31)
at org.adridadou.ethereum.provider.MainEthereumFacadeProvider.getKey(MainEthereumFacadeProvider.java:30)
at org.adridadou.TestnetConnectionTest.run(TestnetConnectionTest.java:36)
at org.adridadou.TestnetConnectionTest.run(TestnetConnectionTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:78)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Right now the keystore mapping works for OSX only.
It needs to work for linux too
Hi
I use mvn compile eth-contract-api-develop
I got this result.
cheer@cheer-H97-D3H:~/mtest/eth-contract-api-develop$ mvn compile
[INFO] argLine set to -javaagent:/home/cheer/.m2/repository/org/jacoco/org.jacoco.agent/0.7.5.201505241946/org.jacoco.agent-0.7.5.201505241946-runtime.jar=destfile=/home/cheer/mtest/eth-contract-api-develop/target/jacoco.exec,excludes=**/*Test.*:**/*Exception.*:**/SolidityContractImpl.*
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ eth-contract-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/cheer/mtest/eth-contract-api-develop/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ eth-contract-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 59 source files to /home/cheer/mtest/eth-contract-api-develop/target/classes
[INFO] /home/cheer/mtest/eth-contract-api-develop/src/main/java/org/adridadou/ethereum/EthereumFacade.java: Some input files use unchecked or unsafe operations.
[INFO] /home/cheer/mtest/eth-contract-api-develop/src/main/java/org/adridadou/ethereum/EthereumFacade.java: Recompile with -Xlint:unchecked for details.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30:27 min
[INFO] Finished at: 2016-10-06T17:33:04+08:00
[INFO] Final Memory: 25M/233M
[INFO] ------------------------------------------------------------------------
what can I do next?
how to run TestnetConnectionTest.java
Thanks !
I try this
mvn exec:java -Dexec.mainClass=org.adridadou.TestnetConnectionTest
but I got
[INFO] --- exec-maven-plugin:1.5.0:java (default-cli) @ eth-contract-api ---
[WARNING]
java.lang.ClassNotFoundException: org.adridadou.TestnetConnectionTest
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:281)
at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 05:44 min
[INFO] Finished at: 2016-10-06T17:47:45+08:00
[INFO] Final Memory: 17M/167M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:java (default-cli) on project eth-contract-api: An exception occured while executing the Java class. org.adridadou.TestnetConnectionTest -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
To keep identity of the caller, we should sign constant calls with the private key
Having oracles is important.
The library should help integrating an oracle (with oraclize) to verify external data sources
In order to help me creating good example and also as a tool to help the ecosystem around this library,
I should create the project launcheth, a distributed app store, then write about it and show it as an example of how to use the library
We should try to convert each parameter for a specific type constructor.
i.e. nested conversion should be handled.
For example. if a constructor gets an Integer as a parameter, or an Enum, it should be able to convert it beforehand. Other complex types is out of scope. It may be possible but a bit too complex for now
It should be possible to return an enum as a type and match the uint result to an Enum
It can be useful if you want to have the same enum in your smart contract and in your java code
Usually you don't want to expose all your ETH to be hacked by anyone. A bug happens so quickly ...
The idea is the following:
Having a way to send some ETH from a cold storage to the app account. This way we expose an account that may be compromised but doesn't have a lot of fund.
Open questions:
Here is the idea:
With StandaloneEthereum + the interface, it should be fast and easy to test a smart contract.
We should have a way to write simple unit tests for it to make sure it works well.
Right now you need the entire source code to connect to a smart contract. The ABI should suffice
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.