-
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.
When interact with contract method use AbiAddress (#22)
* When interact with contract method use AbiAddress * add new add CfxAddress Co-authored-by: PanaW <[email protected]>
- Loading branch information
Showing
9 changed files
with
150 additions
and
93 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
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
30 changes: 16 additions & 14 deletions
30
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 |
---|---|---|
@@ -1,49 +1,51 @@ | ||
package conflux.web3j.contract.internals; | ||
|
||
import conflux.web3j.types.Address; | ||
import conflux.web3j.Account; | ||
import conflux.web3j.Account.Option; | ||
import conflux.web3j.Cfx; | ||
import conflux.web3j.RpcException; | ||
import conflux.web3j.contract.ContractCall; | ||
import org.web3j.abi.datatypes.Address; | ||
import conflux.web3j.types.CfxAddress; | ||
|
||
public class AdminControl extends ContractCall { | ||
private final static String contract = "0x0888000000000000000000000000000000000000"; | ||
private Account account; // if account not set, can only use getAdmin method | ||
private Address contractAddress; | ||
private CfxAddress contractAddress; | ||
|
||
public AdminControl(Account account, int networkId) { | ||
super(account.getCfx(), new Address(AdminControl.contract, networkId)); | ||
super(account.getCfx(), new CfxAddress(AdminControl.contract, networkId)); | ||
this.contractAddress = new CfxAddress(AdminControl.contract, networkId); | ||
this.account = account; | ||
this.contractAddress = new Address(AdminControl.contract, networkId); | ||
} | ||
|
||
public AdminControl(Cfx cfx) { | ||
super(cfx, new Address(AdminControl.contract, cfx.getIntNetworkId())); | ||
this.contractAddress = new Address(AdminControl.contract, cfx.getIntNetworkId()); | ||
super(cfx, new CfxAddress(AdminControl.contract, cfx.getIntNetworkId())); | ||
this.contractAddress = new CfxAddress(AdminControl.contract, cfx.getIntNetworkId()); | ||
} | ||
|
||
public void setAccount(Account account) { | ||
this.account = account; | ||
} | ||
|
||
public String getAdmin(Address contractAddr) throws RpcException { | ||
return this.callAndGet(org.web3j.abi.datatypes.Address.class, "getAdmin", contractAddr.getABIAddress()); | ||
public Address getAdmin(Address contractAddr) throws RpcException { | ||
String hexAddress = this.callAndGet(Address.class, "getAdmin", contractAddr); | ||
return new Address(hexAddress); | ||
} | ||
|
||
public String destroy (Option option, Address contractAddr) throws Exception { | ||
String admin = getAdmin(contractAddr); | ||
if (!admin.equalsIgnoreCase(account.getAddress().getHexAddress())) { | ||
Address admin = getAdmin(contractAddr); | ||
if (!admin.getValue().equalsIgnoreCase(account.getAddress().getHexAddress())) { | ||
throw new Exception("Administrator privilege required"); | ||
} | ||
return this.account.call(option, this.contractAddress, "destroy", contractAddr.getABIAddress()); | ||
return this.account.call(option, this.contractAddress, "destroy", contractAddr); | ||
} | ||
|
||
public String setAdmin(Option option, Address contractAddr, Address newAdmin) throws Exception { | ||
String admin = getAdmin(contractAddr); | ||
if (!admin.equalsIgnoreCase(account.getAddress().getHexAddress())) { | ||
Address admin = getAdmin(contractAddr); | ||
if (!admin.getValue().equalsIgnoreCase(account.getAddress().getHexAddress())) { | ||
throw new Exception("Administrator privilege required"); | ||
} | ||
return this.account.call(option, this.contractAddress, "setAdmin", contractAddr.getABIAddress(), newAdmin.getABIAddress()); | ||
return this.account.call(option, this.contractAddress, "setAdmin", contractAddr, newAdmin); | ||
} | ||
} |
Oops, something went wrong.