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

Commit

Permalink
Merge pull request #164 from jpmorganchase/Java8
Browse files Browse the repository at this point in the history
Java8
  • Loading branch information
fixanoid committed Mar 17, 2020
2 parents 3c8ac4e + 1f9e7f1 commit 4c0d856
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
package com.jpmorgan.cakeshop.controller;

import com.jpmorgan.cakeshop.error.APIException;
import com.jpmorgan.cakeshop.model.APIData;
import com.jpmorgan.cakeshop.model.APIError;
import com.jpmorgan.cakeshop.model.APIResponse;
import com.jpmorgan.cakeshop.model.Contract;
import com.jpmorgan.cakeshop.model.ContractABI;
import com.jpmorgan.cakeshop.model.*;
import com.jpmorgan.cakeshop.model.ContractABI.Entry.Param;
import com.jpmorgan.cakeshop.model.ContractABI.Function;
import com.jpmorgan.cakeshop.model.SolidityType.Bytes32Type;
import com.jpmorgan.cakeshop.model.Transaction;
import com.jpmorgan.cakeshop.model.TransactionRequest;
import com.jpmorgan.cakeshop.model.TransactionResult;
import com.jpmorgan.cakeshop.model.json.ContractPostJsonRequest;
import com.jpmorgan.cakeshop.service.ContractRegistryService;
import com.jpmorgan.cakeshop.service.ContractService;
import com.jpmorgan.cakeshop.service.ContractService.CodeType;
import com.jpmorgan.cakeshop.service.task.BlockchainInitializerTask;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import org.bouncycastle.util.encoders.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.async.WebAsyncTask;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

@RestController
@RequestMapping(value = "/api/contract",
method = RequestMethod.POST,
Expand Down Expand Up @@ -156,8 +145,13 @@ public ResponseEntity<APIResponse> registry() throws APIException {

@PostMapping("/registry/use")
public ResponseEntity<APIResponse> useRegistry(@RequestBody Map<String, String> body) throws APIException {
contractRegistryService.updateRegistryAddress(body.get("address"));
return registry();
String contractRegistryAddress = body.get("address");
contractRegistryService.updateRegistryAddress(contractRegistryAddress);
if(!contractRegistryService.contractRegistryExists()) {
return new ResponseEntity<>(APIResponse.newSimpleResponse("No registry at address " + contractRegistryAddress), HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(
APIResponse.newSimpleResponse(contractRegistryAddress), HttpStatus.OK);
}

@PostMapping("/registry/deploy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.jpmorgan.cakeshop.model.SolcResponse.GasEstimates;
import com.jpmorgan.cakeshop.service.ContractService.CodeType;
import java.util.Map;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Map;

public class Contract {

public static final String API_DATA_TYPE = "contract";
Expand Down Expand Up @@ -56,11 +57,6 @@ public class Contract {
*/
private GasEstimates gasEstimates;

/**
* Contract interface in solidity code
*/
private String solidityInterface;

/**
* Hash of each method signaature (required for making EVM calls)
*/
Expand Down Expand Up @@ -168,14 +164,6 @@ public void setGasEstimates(GasEstimates gasEstimates) {
this.gasEstimates = gasEstimates;
}

public String getSolidityInterface() {
return solidityInterface;
}

public void setSolidityInterface(String solidityInterface) {
this.solidityInterface = solidityInterface;
}

public Map<String, String> getFunctionHashes() {
return functionHashes;
}
Expand Down
3 changes: 1 addition & 2 deletions cakeshop-api/src/main/webapp/js/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@
var getDetails = function(contract, source, contractName) {
// solidity interface
var details = $('<div class="contractDetails"/>')
.append(textRow('Solidity Interface', contract.get("solidityInterface")));

// function hashes
var funHashes = '';
Expand All @@ -288,7 +287,7 @@
var gasToText = function(g) { return g === null ? 'unknown' : g; };
var text = '';
if ('creation' in data)
text += 'Creation: ' + gasToText(data.creation[0]) + ' + ' + gasToText(data.creation[1]) + '\n';
text += 'Creation: ' + gasToText(data.creation.codeDepositCost) + ' + ' + gasToText(data.creation.executionCost) + '\n';
text += 'External:\n';
for (var fun in data.external) {
text += ' ' + fun + ': ' + gasToText(data.external[fun]) + '\n';
Expand Down
6 changes: 6 additions & 0 deletions cakeshop-api/src/main/webapp/js/widgets/contract-list.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import utils from '../utils'

module.exports = function() {
var extended = {
name: 'contract-list',
Expand Down Expand Up @@ -118,15 +120,18 @@ module.exports = function() {
var _this = this;

if (e.target.id === "deploy-registry") {
$(e.target).attr('disabled', 'disabled');
$.when(
utils.load({url: 'api/contract/registry/deploy', data: {}})
).fail(function (res) {
console.log("Failed to deploy contract registry", res);
alert("Failed to deploy contract registry. Please try again or check the logs to see what went wrong.")
_this.updateView(res);
}).done(function (res) {
_this.updateView(res);
})
} else if (e.target.id === "use-existing") {
$(e.target).attr('disabled', 'disabled');
let address = $('#registry-address').val();
$.when(
utils.load({
Expand All @@ -135,6 +140,7 @@ module.exports = function() {
})
).fail(function (res) {
console.log("Failed to set contract registry address", res);
alert(res.responseJSON.data.attributes.result)
_this.updateView(res);
}).done(function (res) {
_this.updateView(res);
Expand Down
7 changes: 4 additions & 3 deletions cakeshop-api/src/main/webapp/js/widgets/node-control.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import utils from '../utils';
import utils from '../utils'

module.exports = function() {
var extended = {
Expand Down Expand Up @@ -69,11 +69,12 @@ module.exports = function() {
utils.load({ url: widget.url.nodeControl + '/' + action })
).done(function() {
_this.removeAttr('disabled');
if(action === 'start') {
if(action !== 'stop') {
window.location.reload()
}
}).fail(function() {
// TODO: fill in
_this.removeAttr('disabled');
alert("Action failed, please check the logs or try again.")
});
}
};
Expand Down

0 comments on commit 4c0d856

Please sign in to comment.