diff --git a/dist/ethereum-1.0.jar b/dist/ethereum-1.0.jar index ff7a774..66cce5f 100644 Binary files a/dist/ethereum-1.0.jar and b/dist/ethereum-1.0.jar differ diff --git a/ethereum/src/main/java/com/crumbs/rest/MockDataCtrl.java b/ethereum/src/main/java/com/crumbs/rest/MockDataCtrl.java index 1af466a..9a8ae48 100644 --- a/ethereum/src/main/java/com/crumbs/rest/MockDataCtrl.java +++ b/ethereum/src/main/java/com/crumbs/rest/MockDataCtrl.java @@ -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; @@ -48,9 +46,6 @@ public class MockDataCtrl { @Autowired private ContractService contractService; - @Autowired - private WebSocketSrvc webSocketSrvc; - @Autowired private InventoryService inventoryService; @@ -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 { diff --git a/ethereum/src/main/java/com/crumbs/services/ContractService.java b/ethereum/src/main/java/com/crumbs/services/ContractService.java index 3265942..b002b6c 100644 --- a/ethereum/src/main/java/com/crumbs/services/ContractService.java +++ b/ethereum/src/main/java/com/crumbs/services/ContractService.java @@ -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]); - } } diff --git a/ethereum/src/main/java/com/crumbs/services/WebSocketSrvc.java b/ethereum/src/main/java/com/crumbs/services/WebSocketSrvc.java deleted file mode 100644 index 7d38c91..0000000 --- a/ethereum/src/main/java/com/crumbs/services/WebSocketSrvc.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.crumbs.services; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.messaging.simp.SimpMessagingTemplate; -import org.springframework.stereotype.Service; - -/** - * Created by low on 18/2/17 6:08 PM. - * @deprecated web socket not working with electron - */ -@Service -public class WebSocketSrvc { - @Autowired - SimpMessagingTemplate messagingTemplate; - - public void sendBalance(long balance) { - String url = "/topics/balance"; - messagingTemplate.convertAndSend(url, balance); - } -} diff --git a/ethereum/src/main/java/com/crumbs/util/DateUtil.java b/ethereum/src/main/java/com/crumbs/util/DateUtil.java index c2c0b93..a106af1 100644 --- a/ethereum/src/main/java/com/crumbs/util/DateUtil.java +++ b/ethereum/src/main/java/com/crumbs/util/DateUtil.java @@ -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) { diff --git a/ethereum/src/test/java/com/crumbs/test/MatchMakingTest.java b/ethereum/src/test/java/com/crumbs/test/MatchMakingTest.java deleted file mode 100644 index 062ab31..0000000 --- a/ethereum/src/test/java/com/crumbs/test/MatchMakingTest.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.crumbs.test; - -import com.alibaba.fastjson.JSON; -import com.crumbs.entities.Member; -import com.crumbs.entities.TxAccepted; -import com.crumbs.models.ExceShipVM; -import com.crumbs.repositories.MemberRepo; -import com.crumbs.services.MatchMakingSrvc; -import com.crumbs.util.DateUtil; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.List; - -/** - * Created by low on 24/2/17 5:19 PM. - */ - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -public class MatchMakingTest { - - private static final Logger logger = LoggerFactory.getLogger(MatchMakingTest.class); - - @Autowired - MatchMakingSrvc matchMakingSrvc; - - @Autowired - MemberRepo memberRepo; - - @Before - public void setUp() { - Member own = new Member(); - byte[] addr = {0x3e, 0x2f}; - own.setAddr(addr); - own.setName("NTUC Bedok Mall"); - own.setX(100); - own.setY(80); - own.setOwn(true); - memberRepo.save(own); - } - - @Test - public void testMatchMake() { - - Member own = memberRepo.findByOwn(true).get(0); - - Member mem1 = new Member(new byte[0], "Giant Tampines Mall", "loc", 13, 14, false); - Member mem2 = new Member(new byte[0], "Cold Storage Katong V", "loc", 53, 3, false); - Member mem3 = new Member(new byte[0], "Lee Minimart Katong V", "loc", 23, 88, false); - Member mem4 = new Member(new byte[0], "Bedok Givers Charity", "loc", 45, 60, false); - //TODO add more members - - Calendar cal = Calendar.getInstance(); - - List tx_list = new ArrayList<>(); - int numTransactions = 10; - List prices = new ArrayList<>(Arrays.asList(1500L, 50L,400L,600L,250L,420L,10L,1300L,550L,350L)); - List names = new ArrayList<>(Arrays.asList("Parmesan Cheese","Onion","Sardines", - "Marigold Milk","Carrot","Corn","Carrot", - "Parmesan Cheese","Onion","Marigold Milk")); - List quantities = new ArrayList<>(Arrays.asList(100,500,430,350,200,300,300,150,500,200)); - - for (int i = 0;i l = new HashSet<>(); - l.add(s); - Shipment s2 = new Shipment(); - s2.setProduct(p); - s2.setQuantity(2); - s2.setExpiry(DateUtil.daysFromToday(8)); - s2.setDateStamp(DateUtil.daysFromToday(2)); - l.add(s2); - Shipment s3 = new Shipment(); - s3.setProduct(p); - s3.setQuantity(3); - s3.setExpiry(DateUtil.daysFromToday(7)); - s3.setDateStamp(DateUtil.daysFromToday(1)); - l.add(s3); - Shipment s4 = new Shipment(); - s4.setProduct(p); - s4.setQuantity(4); - s4.setExpiry(DateUtil.daysFromToday(9)); - s4.setDateStamp(DateUtil.today()); - l.add(s4); - Shipment s5 = new Shipment(); - s5.setProduct(p); - s5.setQuantity(15); - s5.setExpiry(DateUtil.daysFromToday(6)); - s5.setDateStamp(DateUtil.daysFromToday(3)); - l.add(s5); - Shipment s6 = new Shipment(); - s6.setProduct(p); - s6.setQuantity(6); - s6.setExpiry(DateUtil.daysFromToday(7)); - s6.setDateStamp(DateUtil.daysFromToday(0)); - l.add(s6); - Shipment s7 = new Shipment(); - s7.setProduct(p); - s7.setQuantity(36); - s7.setExpiry(DateUtil.daysFromToday(5)); - s7.setDateStamp(DateUtil.daysFromToday(2)); - l.add(s7); - Shipment s8 = new Shipment(); - s8.setProduct(p); - s8.setQuantity(36); - s8.setExpiry(DateUtil.daysFromToday(4)); - s8.setDateStamp(DateUtil.daysFromToday(0)); - l.add(s8); - Shipment s9 = new Shipment(); - s9.setProduct(p); - s9.setQuantity(36); - s9.setExpiry(DateUtil.daysFromToday(14)); - s9.setDateStamp(DateUtil.daysFromToday(7)); - l.add(s9); - p.setShipmentsRecord(l); - SalesRecord r1 = new SalesRecord(); - r1.setQuantity(123456); - r1.setDateStamp(new Date(123456)); - r1.setProduct(p); - SalesRecord r4 = new SalesRecord(); - r4.setQuantity(12345678); - r4.setDateStamp(new Date(12345678)); - r4.setProduct(p); - SalesRecord r2 = new SalesRecord(); - r2.setQuantity(12345); - r2.setDateStamp(new Date(12345)); - r2.setProduct(p); - SalesRecord r3 = new SalesRecord(); - r3.setQuantity(1234567); - r3.setDateStamp(new Date(1234567)); - r3.setProduct(p); - Set records = new HashSet<>(); - records.add(r1); - records.add(r2); - records.add(r3); - records.add(r4); - p.setSalesRecord(records); - - inventoryService.storeProduct(p); - ProductVM outcome = inventoryService.getProduct("test"); - logger.info(JSON.toJSONString(outcome)); - } - - @Test - public void predictionTest() { - String p ="test"; - List list = new ArrayList<>(); - list.add(3); - list.add(4); - list.add(8); - list.add(12); - list.add(68); - list.add(13); - list.add(13); - list.add(19); - logger.info(JSON.toJSONString(predictionSrvc.buildPrediction(list, "test"), true)); - //logger.info(JSON.toJSONString(inventoryService.futureStockInArray(p))); - //logger.info(JSON.toJSONString(predictionSrvc.aggregatedStock(list, p))); - } - - - @Test - public void inventoryMapTest() { - String p = "test"; - logger.info(JSON.toJSONString(inventoryService.futureStock(p))); - logger.info(JSON.toJSONString(inventoryService.futureStockInArray(p))); - } - - @After - public void removeApple() { - inventoryService.deleteProduct("test"); - } - -} diff --git a/ethereum/src/test/java/com/crumbs/test/TransactionTest.java b/ethereum/src/test/java/com/crumbs/test/TransactionTest.java deleted file mode 100644 index 29da64c..0000000 --- a/ethereum/src/test/java/com/crumbs/test/TransactionTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.crumbs.test; - -import com.alibaba.fastjson.JSON; -import com.crumbs.services.TransactionService; -import com.crumbs.util.UrgencyUtil; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; - -/** - * Created by low on 6/2/17 1:23 PM. - */ -public class TransactionTest { - private static final Logger logger = LoggerFactory.getLogger(TransactionTest.class); - - @Test - public void test() { - logger.info(JSON.toJSONString(UrgencyUtil.excessUrg(23, -6 ))); - } - - @Test - public void random() { - logger.info(LocalDateTime.now(ZoneId.of("GMT")).toString()); - } -}