Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 31 additions & 19 deletions src/main/java/io/blk/erc20/ContractService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String deploy(
}

public String name(String contractAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress);
HumanStandardToken humanStandardToken = load(contractAddress,"",false);
try {
return humanStandardToken.name().send();
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -67,8 +67,8 @@ public String name(String contractAddress) throws Exception {
}

public TransactionResponse<ApprovalEventResponse> approve(
List<String> privateFor, String contractAddress, String spender, BigInteger value) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress, privateFor);
List<String> privateFor, String contractAddress, String spender, BigInteger value, String ownerAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress, privateFor,ownerAddress,true);
try {
TransactionReceipt transactionReceipt = humanStandardToken
.approve(spender, value).send();
Expand All @@ -79,7 +79,7 @@ public TransactionResponse<ApprovalEventResponse> approve(
}

public long totalSupply(String contractAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress);
HumanStandardToken humanStandardToken = load(contractAddress,"",false);
try {
return extractLongValue(humanStandardToken.totalSupply().send());
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -89,7 +89,7 @@ public long totalSupply(String contractAddress) throws Exception {

public TransactionResponse<TransferEventResponse> transferFrom(
List<String> privateFor, String contractAddress, String from, String to, BigInteger value) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress, privateFor);
HumanStandardToken humanStandardToken = load(contractAddress, privateFor,"",false);
try {
TransactionReceipt transactionReceipt = humanStandardToken
.transferFrom(from, to, value).send();
Expand All @@ -100,7 +100,7 @@ public TransactionResponse<TransferEventResponse> transferFrom(
}

public long decimals(String contractAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress);
HumanStandardToken humanStandardToken = load(contractAddress,"",false);
try {
return extractLongValue(humanStandardToken.decimals().send());
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -109,7 +109,7 @@ public long decimals(String contractAddress) throws Exception {
}

public String version(String contractAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress);
HumanStandardToken humanStandardToken = load(contractAddress,"",false);
try {
return humanStandardToken.version().send();
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -118,7 +118,7 @@ public String version(String contractAddress) throws Exception {
}

public long balanceOf(String contractAddress, String ownerAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress);
HumanStandardToken humanStandardToken = load(contractAddress,"",false);
try {
return extractLongValue(humanStandardToken.balanceOf(ownerAddress).send());
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -127,7 +127,7 @@ public long balanceOf(String contractAddress, String ownerAddress) throws Except
}

public String symbol(String contractAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress);
HumanStandardToken humanStandardToken = load(contractAddress,"",false);
try {
return humanStandardToken.symbol().send();
} catch (InterruptedException | ExecutionException e) {
Expand All @@ -136,8 +136,8 @@ public String symbol(String contractAddress) throws Exception {
}

public TransactionResponse<TransferEventResponse> transfer(
List<String> privateFor, String contractAddress, String to, BigInteger value) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress, privateFor);
List<String> privateFor, String contractAddress, String to, BigInteger value, String fromAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress, privateFor,fromAddress,true);
try {
TransactionReceipt transactionReceipt = humanStandardToken
.transfer(to, value).send();
Expand All @@ -150,7 +150,7 @@ public TransactionResponse<TransferEventResponse> transfer(
public TransactionResponse<ApprovalEventResponse> approveAndCall(
List<String> privateFor, String contractAddress, String spender, BigInteger value,
String extraData) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress, privateFor);
HumanStandardToken humanStandardToken = load(contractAddress, privateFor,"",false);
try {
TransactionReceipt transactionReceipt = humanStandardToken
.approveAndCall(
Expand All @@ -164,7 +164,7 @@ public TransactionResponse<ApprovalEventResponse> approveAndCall(
}

public long allowance(String contractAddress, String ownerAddress, String spenderAddress) throws Exception {
HumanStandardToken humanStandardToken = load(contractAddress);
HumanStandardToken humanStandardToken = load(contractAddress,"",false);
try {
return extractLongValue(humanStandardToken.allowance(
ownerAddress, spenderAddress)
Expand All @@ -174,16 +174,28 @@ public long allowance(String contractAddress, String ownerAddress, String spende
}
}

private HumanStandardToken load(String contractAddress, List<String> privateFor) {
TransactionManager transactionManager = new ClientTransactionManager(
quorum, nodeConfiguration.getFromAddress(), privateFor);
private HumanStandardToken load(String contractAddress, List<String> privateFor, String fromAddress, boolean withFromAddress) {
TransactionManager transactionManager = null;
if(withFromAddress){
transactionManager = new ClientTransactionManager(
quorum, fromAddress, privateFor);
}else{
transactionManager = new ClientTransactionManager(
quorum, nodeConfiguration.getFromAddress(), privateFor);
}
return HumanStandardToken.load(
contractAddress, quorum, transactionManager, GAS_PRICE, GAS_LIMIT);
}

private HumanStandardToken load(String contractAddress) {
TransactionManager transactionManager = new ClientTransactionManager(
quorum, nodeConfiguration.getFromAddress(), Collections.emptyList());
private HumanStandardToken load(String contractAddress,String fromAddress, boolean withFromAddress ) {
TransactionManager transactionManager = null;
if(withFromAddress){
transactionManager = new ClientTransactionManager(
quorum, fromAddress, Collections.emptyList());
}else{
transactionManager = new ClientTransactionManager(
quorum, nodeConfiguration.getFromAddress(), Collections.emptyList());
}
return HumanStandardToken.load(
contractAddress, quorum, transactionManager, GAS_PRICE, GAS_LIMIT);
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/io/blk/erc20/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ TransactionResponse<ContractService.ApprovalEventResponse> approve(
extractPrivateFor(request),
contractAddress,
approveRequest.getSpender(),
approveRequest.getValue());
approveRequest.getValue(),
approveRequest.getOwner());
}

@ApiOperation("Get total supply of tokens")
Expand Down Expand Up @@ -158,7 +159,8 @@ TransactionResponse<ContractService.TransferEventResponse> transfer(
extractPrivateFor(request),
contractAddress,
transferRequest.getTo(),
transferRequest.getValue());
transferRequest.getValue(),
transferRequest.getFrom());
}

@ApiOperation(
Expand Down Expand Up @@ -214,6 +216,7 @@ static class ContractSpecification {
static class ApproveRequest {
private final String spender;
private final BigInteger value;
private final String owner;
}

@Data
Expand All @@ -227,6 +230,7 @@ static class TransferFromRequest {
static class TransferRequest {
private final String to;
private final BigInteger value;
private final String from;
}

@Data
Expand Down