Skip to content
This repository was archived by the owner on May 27, 2022. It is now read-only.

Commit 4c0d856

Browse files
authored
Merge pull request #164 from jpmorganchase/Java8
Java8
2 parents 3c8ac4e + 1f9e7f1 commit 4c0d856

File tree

5 files changed

+27
-39
lines changed

5 files changed

+27
-39
lines changed

cakeshop-api/src/main/java/com/jpmorgan/cakeshop/controller/ContractController.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,31 @@
11
package com.jpmorgan.cakeshop.controller;
22

33
import com.jpmorgan.cakeshop.error.APIException;
4-
import com.jpmorgan.cakeshop.model.APIData;
5-
import com.jpmorgan.cakeshop.model.APIError;
6-
import com.jpmorgan.cakeshop.model.APIResponse;
7-
import com.jpmorgan.cakeshop.model.Contract;
8-
import com.jpmorgan.cakeshop.model.ContractABI;
4+
import com.jpmorgan.cakeshop.model.*;
95
import com.jpmorgan.cakeshop.model.ContractABI.Entry.Param;
106
import com.jpmorgan.cakeshop.model.ContractABI.Function;
117
import com.jpmorgan.cakeshop.model.SolidityType.Bytes32Type;
12-
import com.jpmorgan.cakeshop.model.Transaction;
13-
import com.jpmorgan.cakeshop.model.TransactionRequest;
14-
import com.jpmorgan.cakeshop.model.TransactionResult;
158
import com.jpmorgan.cakeshop.model.json.ContractPostJsonRequest;
169
import com.jpmorgan.cakeshop.service.ContractRegistryService;
1710
import com.jpmorgan.cakeshop.service.ContractService;
1811
import com.jpmorgan.cakeshop.service.ContractService.CodeType;
1912
import com.jpmorgan.cakeshop.service.task.BlockchainInitializerTask;
2013
import io.swagger.annotations.ApiImplicitParam;
2114
import io.swagger.annotations.ApiImplicitParams;
22-
import java.util.ArrayList;
23-
import java.util.List;
24-
import java.util.Map;
25-
import java.util.concurrent.Callable;
2615
import org.bouncycastle.util.encoders.Base64;
2716
import org.springframework.beans.factory.annotation.Autowired;
2817
import org.springframework.context.ApplicationContext;
2918
import org.springframework.http.HttpStatus;
3019
import org.springframework.http.MediaType;
3120
import org.springframework.http.ResponseEntity;
32-
import org.springframework.web.bind.annotation.GetMapping;
33-
import org.springframework.web.bind.annotation.PostMapping;
34-
import org.springframework.web.bind.annotation.RequestBody;
35-
import org.springframework.web.bind.annotation.RequestMapping;
36-
import org.springframework.web.bind.annotation.RequestMethod;
37-
import org.springframework.web.bind.annotation.RestController;
21+
import org.springframework.web.bind.annotation.*;
3822
import org.springframework.web.context.request.async.WebAsyncTask;
3923

24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import java.util.Map;
27+
import java.util.concurrent.Callable;
28+
4029
@RestController
4130
@RequestMapping(value = "/api/contract",
4231
method = RequestMethod.POST,
@@ -156,8 +145,13 @@ public ResponseEntity<APIResponse> registry() throws APIException {
156145

157146
@PostMapping("/registry/use")
158147
public ResponseEntity<APIResponse> useRegistry(@RequestBody Map<String, String> body) throws APIException {
159-
contractRegistryService.updateRegistryAddress(body.get("address"));
160-
return registry();
148+
String contractRegistryAddress = body.get("address");
149+
contractRegistryService.updateRegistryAddress(contractRegistryAddress);
150+
if(!contractRegistryService.contractRegistryExists()) {
151+
return new ResponseEntity<>(APIResponse.newSimpleResponse("No registry at address " + contractRegistryAddress), HttpStatus.BAD_REQUEST);
152+
}
153+
return new ResponseEntity<>(
154+
APIResponse.newSimpleResponse(contractRegistryAddress), HttpStatus.OK);
161155
}
162156

163157
@PostMapping("/registry/deploy")

cakeshop-api/src/main/java/com/jpmorgan/cakeshop/model/Contract.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import com.fasterxml.jackson.annotation.JsonIgnore;
44
import com.jpmorgan.cakeshop.model.SolcResponse.GasEstimates;
55
import com.jpmorgan.cakeshop.service.ContractService.CodeType;
6-
import java.util.Map;
76
import org.apache.commons.lang3.builder.ToStringBuilder;
87
import org.apache.commons.lang3.builder.ToStringStyle;
98

9+
import java.util.Map;
10+
1011
public class Contract {
1112

1213
public static final String API_DATA_TYPE = "contract";
@@ -56,11 +57,6 @@ public class Contract {
5657
*/
5758
private GasEstimates gasEstimates;
5859

59-
/**
60-
* Contract interface in solidity code
61-
*/
62-
private String solidityInterface;
63-
6460
/**
6561
* Hash of each method signaature (required for making EVM calls)
6662
*/
@@ -168,14 +164,6 @@ public void setGasEstimates(GasEstimates gasEstimates) {
168164
this.gasEstimates = gasEstimates;
169165
}
170166

171-
public String getSolidityInterface() {
172-
return solidityInterface;
173-
}
174-
175-
public void setSolidityInterface(String solidityInterface) {
176-
this.solidityInterface = solidityInterface;
177-
}
178-
179167
public Map<String, String> getFunctionHashes() {
180168
return functionHashes;
181169
}

cakeshop-api/src/main/webapp/js/sandbox.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@
268268
var getDetails = function(contract, source, contractName) {
269269
// solidity interface
270270
var details = $('<div class="contractDetails"/>')
271-
.append(textRow('Solidity Interface', contract.get("solidityInterface")));
272271

273272
// function hashes
274273
var funHashes = '';
@@ -288,7 +287,7 @@
288287
var gasToText = function(g) { return g === null ? 'unknown' : g; };
289288
var text = '';
290289
if ('creation' in data)
291-
text += 'Creation: ' + gasToText(data.creation[0]) + ' + ' + gasToText(data.creation[1]) + '\n';
290+
text += 'Creation: ' + gasToText(data.creation.codeDepositCost) + ' + ' + gasToText(data.creation.executionCost) + '\n';
292291
text += 'External:\n';
293292
for (var fun in data.external) {
294293
text += ' ' + fun + ': ' + gasToText(data.external[fun]) + '\n';

cakeshop-api/src/main/webapp/js/widgets/contract-list.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import utils from '../utils'
2+
13
module.exports = function() {
24
var extended = {
35
name: 'contract-list',
@@ -118,15 +120,18 @@ module.exports = function() {
118120
var _this = this;
119121

120122
if (e.target.id === "deploy-registry") {
123+
$(e.target).attr('disabled', 'disabled');
121124
$.when(
122125
utils.load({url: 'api/contract/registry/deploy', data: {}})
123126
).fail(function (res) {
124127
console.log("Failed to deploy contract registry", res);
128+
alert("Failed to deploy contract registry. Please try again or check the logs to see what went wrong.")
125129
_this.updateView(res);
126130
}).done(function (res) {
127131
_this.updateView(res);
128132
})
129133
} else if (e.target.id === "use-existing") {
134+
$(e.target).attr('disabled', 'disabled');
130135
let address = $('#registry-address').val();
131136
$.when(
132137
utils.load({
@@ -135,6 +140,7 @@ module.exports = function() {
135140
})
136141
).fail(function (res) {
137142
console.log("Failed to set contract registry address", res);
143+
alert(res.responseJSON.data.attributes.result)
138144
_this.updateView(res);
139145
}).done(function (res) {
140146
_this.updateView(res);

cakeshop-api/src/main/webapp/js/widgets/node-control.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import utils from '../utils';
1+
import utils from '../utils'
22

33
module.exports = function() {
44
var extended = {
@@ -69,11 +69,12 @@ module.exports = function() {
6969
utils.load({ url: widget.url.nodeControl + '/' + action })
7070
).done(function() {
7171
_this.removeAttr('disabled');
72-
if(action === 'start') {
72+
if(action !== 'stop') {
7373
window.location.reload()
7474
}
7575
}).fail(function() {
76-
// TODO: fill in
76+
_this.removeAttr('disabled');
77+
alert("Action failed, please check the logs or try again.")
7778
});
7879
}
7980
};

0 commit comments

Comments
 (0)