-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add support for internal contract * add support for internal contract * add read methods to internal contracts * update internal contracts * add internal contract api * sync * remove abi jsø˜ * update contracts * update erc20 and erc777 * update default chanId to 1029 * fix spell and equal
- Loading branch information
Showing
13 changed files
with
347 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,5 @@ gradle-app.setting | |
.classpath | ||
.settings/ | ||
bin | ||
.idea | ||
.idea | ||
todo.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
### 0.9.0 | ||
|
||
1. Tx receipts return more info: txExecErrorMsg, gasCoveredBySponsor, storageCoveredBySponsor, storageCollateralized, storageReleased | ||
2. Add new RPC methods: cfx_getDepositList, cfx_getVoteList, cfx_getSupplyInfo | ||
3. Add support for InternalContracts | ||
4. Merge ERC20, ERC777 call and executor | ||
5. Update default gasPrice to 1 Drip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package conflux.web3j.contract; | ||
|
||
import conflux.web3j.Account; | ||
import conflux.web3j.Cfx; | ||
import conflux.web3j.RpcException; | ||
import conflux.web3j.contract.abi.DecodeUtil; | ||
import org.web3j.abi.datatypes.Address; | ||
import org.web3j.abi.datatypes.generated.Uint256; | ||
|
||
import java.math.BigInteger; | ||
|
||
public class ERC20 extends ContractCall{ | ||
private Account account; | ||
private String contract; | ||
|
||
public ERC20(Cfx cfx, String address) { | ||
super(cfx, address); | ||
} | ||
|
||
public ERC20(Cfx cfx, String address, Account account) { | ||
super(cfx, address); | ||
this.account = account; | ||
this.contract = address; | ||
} | ||
|
||
public BigInteger totalSupply() throws RpcException { | ||
return this.callAndGet(Uint256.class, "totalSupply"); | ||
} | ||
|
||
public BigInteger balanceOf(String account) throws RpcException { | ||
return this.callAndGet(Uint256.class, "balanceOf", new Address(account)); | ||
} | ||
|
||
public BigInteger allowance(String owner, String spender) throws RpcException { | ||
return this.callAndGet(Uint256. class, "allowance", new Address(owner), new Address(spender)); | ||
} | ||
|
||
public String transfer(Account.Option option, String recipient, BigInteger amount) throws Exception { | ||
return this.account.call(option, this.contract, "transfer", new Address(recipient), new Uint256(amount)); | ||
} | ||
|
||
public String approve(Account.Option option, String spender, BigInteger amount) throws Exception { | ||
return this.account.call(option, this.contract, "approve", new Address(spender), new Uint256(amount)); | ||
} | ||
|
||
public String transferFrom(Account.Option option, String sender, String recipient, BigInteger amount) throws Exception { | ||
return this.account.call(option, this.contract, "transferFrom", new Address(sender), new Address(recipient), new Uint256(amount)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package conflux.web3j.contract; | ||
|
||
import conflux.web3j.Account; | ||
import conflux.web3j.Cfx; | ||
import conflux.web3j.RpcException; | ||
import conflux.web3j.contract.abi.DecodeUtil; | ||
import org.web3j.abi.TypeReference; | ||
import org.web3j.abi.datatypes.*; | ||
import org.web3j.abi.datatypes.generated.Uint256; | ||
|
||
import java.math.BigInteger; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ERC777 extends ContractCall { | ||
private Account account; | ||
private String contract; | ||
|
||
private static final TypeReference<DynamicArray<Address>> TYPE_DYNAMIC_ARRAY_ADDRESS = new TypeReference<DynamicArray<Address>>() {}; | ||
|
||
public ERC777(Cfx cfx, String erc777Address) { | ||
super(cfx, erc777Address); | ||
} | ||
|
||
public ERC777(Cfx cfx, String address, Account account) { | ||
super(cfx, address); | ||
this.account = account; | ||
this.contract = address; | ||
} | ||
|
||
public String name() throws RpcException { | ||
return this.callAndGet(Utf8String.class, "name"); | ||
} | ||
|
||
public String symbol() throws RpcException { | ||
return this.callAndGet(Utf8String.class, "symbol"); | ||
} | ||
|
||
public BigInteger granularity() throws RpcException { | ||
return this.callAndGet(Uint256.class, "granularity"); | ||
} | ||
|
||
public BigInteger totalSupply() throws RpcException { | ||
return this.callAndGet(Uint256.class, "totalSupply"); | ||
} | ||
|
||
public BigInteger balanceOf(String owner) throws RpcException { | ||
return this.callAndGet(Uint256.class, "balanceOf", new Address(owner)); | ||
} | ||
|
||
public boolean isOperatorFor(String operator, String tokenHolder) throws RpcException { | ||
return this.callAndGet(Bool.class, "isOperatorFor", new Address(operator), new Address(tokenHolder)); | ||
} | ||
|
||
public List<String> defaultOperators() throws RpcException { | ||
String encodedResult = this.call("defaultOperators").sendAndGet(); | ||
List<Address> operators = DecodeUtil.decode(encodedResult, TYPE_DYNAMIC_ARRAY_ADDRESS); | ||
|
||
return operators.stream() | ||
.map(address -> address.getValue()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
public String send(Account.Option option, String recipient, BigInteger amount, byte[] data) throws Exception { | ||
return this.account.call(option, this.contract, "send", new Address(recipient), new Uint256(amount), new DynamicBytes(data)); | ||
} | ||
|
||
public String burn(Account.Option option, BigInteger amount, byte[] data) throws Exception { | ||
return this.account.call(option, this.contract, "burn", new Uint256(amount), new DynamicBytes(data)); | ||
} | ||
|
||
public String authorizeOperator(Account.Option option, String operator) throws Exception { | ||
return this.account.call(option, this.contract, "authorizeOperator", new Address(operator)); | ||
} | ||
|
||
public String revokeOperator(Account.Option option, String operator) throws Exception { | ||
return this.account.call(option, this.contract, "revokeOperator", new Address(operator)); | ||
} | ||
|
||
public String operatorSend(Account.Option option, String sender, String recipient, BigInteger amount, byte[] data, byte[] operatorData) throws Exception { | ||
return this.account.call(option, this.contract, "operatorSend", new Address(sender), new Address(recipient), new Uint256(amount), new DynamicBytes(data), new DynamicBytes(operatorData)); | ||
} | ||
|
||
public String operatorBurn(Account.Option option, String account, BigInteger amount, byte[] data, byte[] operatorData) throws Exception { | ||
return this.account.call(option, this.contract, "operatorBurn", new Address(account), new Uint256(amount), new DynamicBytes(data), new DynamicBytes(operatorData)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/conflux/web3j/contract/internals/AdminControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package conflux.web3j.contract.internals; | ||
|
||
import conflux.web3j.Account; | ||
import conflux.web3j.Account.Option; | ||
import conflux.web3j.RpcException; | ||
import conflux.web3j.contract.ContractCall; | ||
import conflux.web3j.contract.abi.DecodeUtil; | ||
import org.web3j.abi.datatypes.Address; | ||
import conflux.web3j.Cfx; | ||
|
||
public class AdminControl extends ContractCall { | ||
private final static String contract = "0x0888000000000000000000000000000000000000"; | ||
private Account account; // if account not set, can only use getAdmin method | ||
|
||
public AdminControl(Account account) { | ||
super(account.getCfx(), AdminControl.contract); | ||
this.account = account; | ||
} | ||
|
||
public AdminControl(Cfx cfx) { | ||
super(cfx, AdminControl.contract); | ||
} | ||
|
||
public void setAccount(Account account) { | ||
this.account = account; | ||
} | ||
|
||
public String getAdmin(String contractAddr) throws RpcException { | ||
return this.callAndGet(Address.class, "getAdmin", new Address(contractAddr)); | ||
} | ||
|
||
public String destroy (Option option, String contractAddr) throws Exception { | ||
String admin = getAdmin(contractAddr); | ||
if (!admin.equalsIgnoreCase(account.getAddress())) { | ||
throw new Exception("Administrator privilege required"); | ||
} | ||
return this.account.call(option, contract, "destroy", new Address(contractAddr)); | ||
} | ||
|
||
public String setAdmin(Option option, String contractAddr, String newAdmin) throws Exception { | ||
String admin = getAdmin(contractAddr); | ||
if (!admin.equalsIgnoreCase(account.getAddress())) { | ||
throw new Exception("Administrator privilege required"); | ||
} | ||
return this.account.call(option, contract, "setAdmin", new Address(contractAddr), new Address(newAdmin)); | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/conflux/web3j/contract/internals/SponsorWhitelistControl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package conflux.web3j.contract.internals; | ||
|
||
import conflux.web3j.Account; | ||
|
||
import java.math.BigInteger; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import conflux.web3j.Cfx; | ||
import conflux.web3j.RpcException; | ||
import conflux.web3j.contract.ContractCall; | ||
import conflux.web3j.contract.abi.DecodeUtil; | ||
import org.web3j.abi.datatypes.Address; | ||
import org.web3j.abi.datatypes.Bool; | ||
import org.web3j.abi.datatypes.DynamicArray; | ||
import org.web3j.abi.datatypes.generated.Uint256; | ||
|
||
public class SponsorWhitelistControl extends ContractCall { | ||
private final static String contract = "0x0888000000000000000000000000000000000001"; | ||
private Account account; | ||
|
||
public SponsorWhitelistControl(Account account) { | ||
super(account.getCfx(), SponsorWhitelistControl.contract); | ||
this.account = account; | ||
} | ||
|
||
public SponsorWhitelistControl(Cfx cfx) { | ||
super(cfx, SponsorWhitelistControl.contract); | ||
} | ||
|
||
public void setAccount(Account account) { | ||
this.account = account; | ||
} | ||
|
||
public String getSponsorForGas(String contractAddr) throws RpcException { | ||
return this.callAndGet(Address.class, "getSponsorForGas", new Address(contractAddr)); | ||
} | ||
|
||
public BigInteger getSponsoredBalanceForGas(String contractAddr) throws RpcException { | ||
return this.callAndGet(Uint256.class, "getSponsoredBalanceForGas", new Address(contractAddr)); | ||
} | ||
|
||
public BigInteger getSponsoredGasFeeUpperBound(String contractAddr) throws RpcException { | ||
return this.callAndGet(Uint256.class, "getSponsoredGasFeeUpperBound", new Address(contractAddr)); | ||
} | ||
|
||
public String getSponsorForCollateral(String contractAddr) throws RpcException { | ||
return this.callAndGet(Address.class, "getSponsorForCollateral", new Address(contractAddr)); | ||
} | ||
|
||
public BigInteger getSponsoredBalanceForCollateral(String contractAddr) throws RpcException { | ||
return this.callAndGet(Uint256.class, "getSponsoredBalanceForCollateral", new Address(contractAddr)); | ||
} | ||
|
||
public boolean isWhitelisted(String contractAddr, String user) throws RpcException { | ||
return this.callAndGet(Bool.class, "isWhitelisted", new Address(contractAddr), new Address(user)); | ||
} | ||
|
||
public boolean isAllWhitelisted(String contractAddr) throws RpcException { | ||
return this.callAndGet(Bool.class, "isAllWhitelisted", new Address(contractAddr)); | ||
} | ||
|
||
// public void addPrivilege(Account.Option option, String[] addresses) throws Exception { | ||
// List<Address> list = Arrays.stream(addresses).map(a -> new Address(a)).collect(Collectors.toList()); | ||
// account.call(option, contract, "addPrivilege", new DynamicArray<Address>(Address.class, list)); | ||
// } | ||
// | ||
// public void removePrivilege(Account.Option option, String[] addresses) throws Exception { | ||
// List<Address> list = Arrays.stream(addresses).map(a -> new Address(a)).collect(Collectors.toList()); | ||
// account.call(option, contract, "removePrivilege", new DynamicArray<Address>(Address.class, list)); | ||
// } | ||
|
||
public String setSponsorForCollateral(Account.Option option, String contractAddr) throws Exception { | ||
return account.call(option, contract, "setSponsorForCollateral", new Address(contractAddr)); | ||
} | ||
|
||
public String setSponsorForGas(Account.Option option, String contractAddr, BigInteger upperBound) throws Exception { | ||
return account.call(option, contract, "setSponsorForGas", new Address(contractAddr), new Uint256(upperBound)); | ||
} | ||
|
||
public String addPrivilegeByAdmin(Account.Option option, String contractAddr, String[] address) throws Exception { | ||
List<Address> list = Arrays.stream(address).map(a -> new Address(a)).collect(Collectors.toList()); | ||
return account.call(option, contract, "addPrivilegeByAdmin", new Address(contractAddr), new DynamicArray<Address>(Address.class, list)); | ||
} | ||
|
||
public String removePrivilegeByAdmin(Account.Option option, String contractAddr, String[] address) throws Exception { | ||
List<Address> list = Arrays.stream(address).map(a -> new Address(a)).collect(Collectors.toList()); | ||
return account.call(option, contract, "removePrivilegeByAdmin", new Address(contractAddr), new DynamicArray<Address>(Address.class, list)); | ||
} | ||
} |
Oops, something went wrong.