Skip to content

Commit

Permalink
smaller file size
Browse files Browse the repository at this point in the history
  • Loading branch information
lhhong committed May 7, 2017
1 parent a179963 commit d8dfd9e
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 485 deletions.
Binary file modified dist/ethereum-1.0.jar
Binary file not shown.
35 changes: 0 additions & 35 deletions ethereum/src/main/java/com/crumbs/rest/MockDataCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import com.crumbs.services.ContractService;
import com.crumbs.services.InventoryService;
import com.crumbs.services.TransactionService;
import com.crumbs.services.WebSocketSrvc;
import com.crumbs.util.CrumbsUtil;
import com.crumbs.util.DateUtil;
import com.crumbs.util.TxCancelledException;
import org.ethereum.crypto.ECKey;
Expand Down Expand Up @@ -48,9 +46,6 @@ public class MockDataCtrl {
@Autowired
private ContractService contractService;

@Autowired
private WebSocketSrvc webSocketSrvc;

@Autowired
private InventoryService inventoryService;

Expand Down Expand Up @@ -170,36 +165,6 @@ public void receive(@RequestBody Product p) {
inventoryService.storeProduct(p);
}

@RequestMapping(value = "/sample-contract", method = GET)
@ResponseBody
public void sendSampleContract() throws IOException {
contractService.testContract();
}

@RequestMapping(value = "/modify-sample-contract", method = GET)
@ResponseBody
public void modifySampleContract() throws IOException, TxCancelledException {
contractService.modifyMortalGreeting();
}

@RequestMapping(value = "/test-sample-contract", method = GET)
@ResponseBody
public void testSampleContract() throws IOException {
contractService.callMortalGreet();
}

@RequestMapping(value = "/bestBlock", method = GET, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public String getBestBlock() throws IOException {
return ethereumBean.getBestBlock();
}

@RequestMapping(value = "/adminInfo", method = GET, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public String getAdminInfo() throws IOException {
return ethereumBean.getAdminInfo();
}

@RequestMapping(value = "/sendMockTx", method = POST, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public void sendMockTx(@RequestParam ("sender") String sender, @RequestParam("receiver") String receiver) throws IOException {
Expand Down
84 changes: 0 additions & 84 deletions ethereum/src/main/java/com/crumbs/services/ContractService.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,88 +204,4 @@ public void topUpContract() throws TxCancelledException {
sendToTxContract("topup", 100);
}

/******************************************************************************/
/*************** OBSOLETE FUNCTIONS NO LONGER USED ****************************/
/******************************************************************************/

//EthereumJ compiler seems to be faulty after contract reached a certain complexity
public void compileAndSend(String contract, String name) throws IOException {
logger.info("Compiling contract...");
SolidityCompiler.Result result = compiler.compileSrc(contract.getBytes(), true, true,
SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
if (result.isFailed()) {
throw new RuntimeException("Contract compilation failed:\n" + result.errors);
}
CompilationResult res = CompilationResult.parse(result.output);
if (res.contracts.isEmpty()) {
throw new RuntimeException("Compilation failed, no contracts returned:\n" + result.errors);
}
CompilationResult.ContractMetadata metadata = res.contracts.values().iterator().next();
if (metadata.bin == null || metadata.bin.isEmpty()) {
throw new RuntimeException("Compilation failed, no binary returned:\n" + result.errors);
}
logger.info("Compiled metadata: " + JSON.toJSONString(metadata, true));

SendingTxListener listener = new SendingTxListener() {
@Override
public void isDone(Transaction tx) {
CrumbsContract crumbsContract = new CrumbsContract();
crumbsContract.setContractName(name);
crumbsContract.setAbi(metadata.abi);
crumbsContract.setBin(metadata.bin);
crumbsContract.setSolc(metadata.solInterface);
crumbsContract.setMetadata(metadata.metadata);
crumbsContract.setContractAddr(tx.getContractAddress());
crumbsContract.setIncluded(false);
logger.info("CONTRACT ADDRESS ON CREATION: " + ByteUtil.toHexString(tx.getContractAddress()));
//crumbsContractRepo.delete("mortal_contract");
crumbsContractRepo.save(crumbsContract);
}

@Override
public void isCancelled() {
logger.warn("transaction cancelled");
//TODO notify of failed tx
}
};
ethereumBean.sendTransaction(Hex.decode(metadata.bin), listener);
}

private final String SAMPLE_CONTRACT = "contract mortal { address owner; function mortal() { owner = msg.sender; } function kill() { if (msg.sender == owner) selfdestruct(owner); } } contract greeter is mortal {string greeting = \"default\"; function changeGreeter(string _greeting) public { greeting = _greeting; } function greet() constant returns (string) { return greeting; } }";

public void testContract() throws IOException{
compileAndSend(SAMPLE_CONTRACT, "mortal_tx");
}

public void modifyMortalGreeting() throws TxCancelledException {

CrumbsContract testContract = crumbsContractRepo.findOne("mortal_tx");
logger.info("loaded contract : " + JSON.toJSONString(testContract, true) );
/*if (!testContract.isIncluded()) {
logger.warn("Contract not yet included to chain");
return;
}*/
logger.info("Calling the contract constructor");
CallTransaction.Contract contract = new CallTransaction.Contract(testContract.getAbi());
byte[] functionCallBytes = contract.getByName("changeGreeter").encode("HI THERE!");
ethereumBean.sendTransaction(testContract.getContractAddr(), functionCallBytes);
logger.info("Contract modified!");

}

public void callMortalGreet() {
CrumbsContract testContract = crumbsContractRepo.findOne("mortal_tx");
logger.info("loaded contract : " + JSON.toJSONString(testContract, true) );
logger.info("Contract address: " + ByteUtil.toHexString(testContract.getContractAddr()));
/*if (!testContract.isIncluded()) {
logger.warn("Contract not yet included to chain");
return;
}*/
CallTransaction.Contract contract = new CallTransaction.Contract(testContract.getAbi());
ProgramResult r = ethereumBean.callConstantFunction(Hex.toHexString(testContract.getContractAddr()), accountBean.getKey(),
contract.getByName("greet"));
Object[] ret = contract.getByName("greet").decodeResult(r.getHReturn());
logger.info("result: " + JSON.toJSONString(ret));
logger.info("Current contract data member value: " + ret[0]);
}
}
20 changes: 0 additions & 20 deletions ethereum/src/main/java/com/crumbs/services/WebSocketSrvc.java

This file was deleted.

2 changes: 1 addition & 1 deletion ethereum/src/main/java/com/crumbs/util/DateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static Date today() {

public static LocalDate todayLocalDate() {
//mock todau's date as 15th April
return LocalDate.ofYearDay(2017,104);
return LocalDate.of(2017,5,11);
}

public static Date addDays(Date date, long days) {
Expand Down
145 changes: 0 additions & 145 deletions ethereum/src/test/java/com/crumbs/test/MatchMakingTest.java

This file was deleted.

13 changes: 0 additions & 13 deletions ethereum/src/test/java/com/crumbs/test/PredictionsTest.java

This file was deleted.

Loading

0 comments on commit d8dfd9e

Please sign in to comment.