public TransactionReceiptImpl(TransactionHusk tx) { this.txId = tx.getHash().toString(); this.issuer = tx.getAddress().toString(); }
/** * Get the address. * * @return address */ public Address getAddress() { try { return new Address(this.coreTransaction.getAddress()); } catch (Exception e) { log.debug(e.getMessage()); return null; } }
@Test public void hexEncodeAndDecodeByteArrayTest() throws Exception { byte[] origin = tx.getAddress().getBytes(); String encoded = Hex.encodeHexString(origin); byte[] decoded = Hex.decodeHex(encoded); assertArrayEquals(decoded, origin); }
protected Branch(JsonObject json) { this.json = json; this.branchId = BranchId.of(json); this.name = json.get("name").getAsString(); this.symbol = json.get("symbol").getAsString(); this.property = json.get("property").getAsString(); String timestampHex = json.get("timestamp").getAsString(); this.timestamp = HexUtil.hexStringToLong(timestampHex); this.rawForSign = rawHashForSign(); this.signature = Sha3Hash.createByHashed(Hex.decode(json.get("signature").getAsString())); this.owner = Address.of(json.get("owner").getAsString()); this.contractId = ContractId.of(json.get("contractId").getAsString()); this.description = json.get("description").getAsString(); }
public boolean verify() { ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signature.getBytes()); try { ECKey ecKeyPub = ECKey.signatureToKey(rawForSign.getBytes(), ecdsaSignature); if (ecKeyPub.verify(rawForSign.getBytes(), ecdsaSignature)) { return new Address(ecKeyPub.getAddress()).equals(owner); } else { return false; } } catch (SignatureException e) { throw new InvalidSignatureException(e); } }
@Test public void testGetAddressWithWallet() { TransactionHusk tx1 = createTransferTx(); TransactionHusk tx2 = createTransferTx(); assertThat(tx1.getAddress()).isEqualTo(tx2.getAddress()); Wallet wallet = TestConstants.wallet(); assertThat(wallet.getAddress()).isEqualTo(tx1.getAddress().getBytes()); }
@Test public void blockAddressTest() { assertThat(block.getAddress().toString()) .isEqualTo("2b8d3ec39e8b8d86a6fcdf5f5fe375f30a6e6c06"); }
@Test public void testGetAddressWithWalletAccount() throws IOException, InvalidCipherTextException { Account account = new Account(); log.debug("Account: " + account.toString()); log.debug("Account.address: " + Hex.toHexString(account.getAddress())); Wallet wallet = new Wallet(account.getKey(), "tmp/path", "nodePri.key", "Aa1234567890!"); log.debug("Wallet: " + wallet.toString()); log.debug("Wallet.address: " + Hex.toHexString(wallet.getAddress())); TransactionHusk tx1 = createTx(wallet); TransactionHusk tx2 = createTx(wallet); log.debug("Test Transaction1: " + tx1.toString()); log.debug("Test Transaction1 Address: " + tx1.getAddress()); log.debug("Test Transaction2: " + tx2.toString()); log.debug("Test Transaction2 Address: " + tx2.getAddress()); assertThat(wallet.getAddress()).isEqualTo(account.getAddress()); assertThat(tx1.getAddress()).isEqualTo(tx2.getAddress()); assertThat(account.getAddress()).isEqualTo(tx1.getAddress().getBytes()); }
public static Address of(String addr) { return new Address(Hex.decode(addr)); } }
public static TransactionDto createBy(TransactionHusk tx) { TransactionDto transactionDto = new TransactionDto(); Proto.Transaction.Header header = tx.getInstance().getHeader(); transactionDto.branchId = Hex.toHexString(header.getChain().toByteArray()); transactionDto.version = Hex.toHexString(header.getVersion().toByteArray()); transactionDto.type = Hex.toHexString(header.getType().toByteArray()); transactionDto.timestamp = ByteUtil.byteArrayToLong(header.getTimestamp().toByteArray()); transactionDto.bodyHash = Hex.toHexString(header.getBodyHash().toByteArray()); transactionDto.bodyLength = ByteUtil.byteArrayToLong(header.getBodyLength().toByteArray()); transactionDto.signature = Hex.toHexString(tx.getInstance().getSignature().toByteArray()); try { transactionDto.body = new ObjectMapper().readValue(tx.getBody(), List.class); } catch (Exception e) { transactionDto.body = null; } transactionDto.author = tx.getAddress().toString(); transactionDto.txId = tx.getHash().toString(); return transactionDto; } }
@Test public void testGetAddressWithSig() throws IOException, InvalidCipherTextException, SignatureException { Account account = new Account(); log.debug("Account: " + account.toString()); log.debug("Account.address: " + Hex.toHexString(account.getAddress())); log.debug("Account.pubKey: " + Hex.toHexString(account.getKey().getPubKey())); Wallet wallet = new Wallet(account.getKey(), "tmp/path", "nodePri.key", "Aa1234567890!"); log.debug("Wallet: " + wallet.toString()); log.debug("Wallet.address: " + Hex.toHexString(wallet.getAddress())); log.debug("Wallet.pubKey: " + Hex.toHexString(wallet.getPubicKey())); TransactionHusk txHusk1 = createTx(wallet); log.debug("Test Transaction1: " + txHusk1.toString()); log.debug("Test Transaction1 Address: " + txHusk1.getAddress()); assertThat(txHusk1.verify()).isTrue(); assertThat(wallet.getAddress()).isEqualTo(account.getAddress()); assertThat(wallet.getAddress()).isEqualTo(txHusk1.getAddress().getBytes()); byte[] hashedRawData = txHusk1.getHashForSigning().getBytes(); log.debug("hashedRawData: " + Hex.toHexString(hashedRawData)); byte[] signatureBin = txHusk1.getInstance().getSignature().toByteArray(); log.debug("signatureBin: " + Hex.toHexString(signatureBin)); ECKey.ECDSASignature ecdsaSignature = new ECKey.ECDSASignature(signatureBin); ECKey key = ECKey.signatureToKey(hashedRawData, ecdsaSignature); byte[] address = key.getAddress(); byte[] pubKey = key.getPubKey(); log.debug("address: " + Hex.toHexString(address)); log.debug("pubKey: " + Hex.toHexString(pubKey)); assertThat(account.getAddress()).isEqualTo(address); assertThat(account.getKey().getPubKey()).isEqualTo(pubKey); }
public Address getAddress() { try { return new Address(this.coreBlock.getAddress()); } catch (Exception e) { throw new NotValidateException(e); } }
private static BlockDto createBy(BlockHusk block, boolean withBody) { BlockDto blockDto = new BlockDto(); Proto.Block.Header header = block.getInstance().getHeader(); blockDto.branchId = Hex.toHexString(header.getChain().toByteArray()); blockDto.version = Hex.toHexString(header.getVersion().toByteArray()); blockDto.type = Hex.toHexString(header.getType().toByteArray()); blockDto.prevBlockId = Hex.toHexString(block.getPrevHash().getBytes()); blockDto.index = block.getIndex(); blockDto.timestamp = ByteUtil.byteArrayToLong(header.getTimestamp().toByteArray()); blockDto.merkleRoot = Hex.toHexString(header.getMerkleRoot().toByteArray()); blockDto.bodyLength = ByteUtil.byteArrayToLong(header.getBodyLength().toByteArray()); blockDto.signature = Hex.toHexString(block.getInstance().getSignature().toByteArray()); blockDto.txSize = block.getBodySize(); if (withBody) { blockDto.body = block.getBody().stream().map(TransactionDto::createBy) .collect(Collectors.toList()); } blockDto.author = block.getAddress().toString(); blockDto.blockId = block.getHash().toString(); return blockDto; }
@Test public void createTest() { String description = "ETH TO YEED"; JsonObject branch = getEthToYeedBranch(description); String branchId = BranchId.of(branch).toString(); JsonObject params = new JsonObject(); params.add(branchId, branch); TransactionReceipt receipt = new TransactionReceiptImpl(); receipt.setIssuer(stateValue.getOwner().toString()); try { txReceiptField.set(stemContract, receipt); receipt = stemContract.create(params); } catch (IllegalAccessException e) { e.printStackTrace(); } assertThat(receipt.isSuccess()).isTrue(); JsonObject saved = stateStore.get(branchId); assertThat(saved).isNotNull(); assertThat(saved.get("description").getAsString()).isEqualTo(description); }
@Test public void defaultTest() { String name = "STEM"; String symbol = "STEM"; String property = "ecosystem"; String description = "The Basis of the YGGDRASH Ecosystem. " + "It is also an aggregate and a blockchain containing information " + "of all Branch Chains."; String contractId = "d399cd6d34288d04ba9e68ddfda9f5fe99dd778e"; String timestamp = "00000166c837f0c9"; JsonObject genesis = new JsonObject(); JsonObject json = ContractTestUtils.createBranchJson(name, symbol, property, description, contractId, timestamp, genesis); Branch branch = Branch.of(json); assertThat(branch.getName()).isEqualTo(name); assertThat(branch.getSymbol()).isEqualTo(symbol); assertThat(branch.getProperty()).isEqualTo(property); assertThat(branch.getDescription()).isEqualTo(description); assertThat(branch.getContractId().toString()).isEqualTo(contractId); assertThat(branch.getTimestamp()) .isEqualTo(HexUtil.hexStringToLong(timestamp)); assertThat(branch.getOwner().toString()).isEqualTo(TestConstants.wallet().getHexAddress()); assertThat(branch.verify()).isTrue(); }
@Before public void setUp() throws IllegalAccessException { stateStore = new StateStore<>(new HashMapDbSource()); stemContract = new StemContract(); JsonObject json = ContractTestUtils.createSampleBranchJson(); stateValue = StemContractStateValue.of(json); JsonObject params = createParams(stateValue.getJson()); TransactionReceipt receipt = new TransactionReceiptImpl(); receipt.setIssuer(stateValue.getOwner().toString()); List<Field> txReceipt = ContractUtils.txReceiptFields(stemContract); if (txReceipt.size() == 1) { txReceiptField = txReceipt.get(0); } for (Field f : ContractUtils.contractFields(stemContract, ContractStateStore.class)) { f.setAccessible(true); f.set(stemContract, stateStore); } try { txReceiptField.set(stemContract, receipt); stemContract.genesis(params); } catch (IllegalAccessException e) { e.printStackTrace(); } }