target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test public void remove() { Assert.assertTrue(whitelist.isWhitelisted(existingAddress)); Assert.assertTrue(whitelist.isWhitelisted(existingAddress.getHash160())); Assert.assertTrue(whitelist.remove(existingAddress)); Assert.assertFalse(whitelist.isWhitelisted(existingAddress)); Assert.assertFalse(whitelist.isWhitelisted(existingAddress.getHash160())); Assert.assertFalse(whitelist.remove(existingAddress)); }
|
public boolean remove(Address address) { return whitelistedAddresses.remove(address) != null; }
|
LockWhitelist { public boolean remove(Address address) { return whitelistedAddresses.remove(address) != null; } }
|
LockWhitelist { public boolean remove(Address address) { return whitelistedAddresses.remove(address) != null; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
|
LockWhitelist { public boolean remove(Address address) { return whitelistedAddresses.remove(address) != null; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
LockWhitelist { public boolean remove(Address address) { return whitelistedAddresses.remove(address) != null; } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
@Test public void consume() { assertExistance(existingAddress, true); whitelist.consume(existingAddress); assertExistance(existingAddress, false); Assert.assertFalse(whitelist.remove(existingAddress)); }
|
public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
@Test public void test1() throws UnknownHostException { String peersPacket = "F8 4E 11 F8 4B C5 36 81 " + "CC 0A 29 82 76 5F B8 40 D8 D6 0C 25 80 FA 79 5C " + "FC 03 13 EF DE BA 86 9D 21 94 E7 9E 7C B2 B5 22 " + "F7 82 FF A0 39 2C BB AB 8D 1B AC 30 12 08 B1 37 " + "E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " + "17 08 9F EA F8 4C 21 B0"; byte[] payload = Hex.decode(peersPacket); byte[] ip = decodeIP4Bytes(payload, 5); assertEquals(InetAddress.getByAddress(ip).toString(), ("/54.204.10.41")); }
|
public static byte[] decodeIP4Bytes(byte[] data, int index) { int offset = 1; final byte[] result = new byte[4]; for (int i = 0; i < 4; i++) { result[i] = decodeOneByteItem(data, index + offset); if ((data[index + offset] & 0xFF) > OFFSET_SHORT_ITEM) { offset += 2; } else { offset += 1; } } return result; }
|
RLP { public static byte[] decodeIP4Bytes(byte[] data, int index) { int offset = 1; final byte[] result = new byte[4]; for (int i = 0; i < 4; i++) { result[i] = decodeOneByteItem(data, index + offset); if ((data[index + offset] & 0xFF) > OFFSET_SHORT_ITEM) { offset += 2; } else { offset += 1; } } return result; } }
|
RLP { public static byte[] decodeIP4Bytes(byte[] data, int index) { int offset = 1; final byte[] result = new byte[4]; for (int i = 0; i < 4; i++) { result[i] = decodeOneByteItem(data, index + offset); if ((data[index + offset] & 0xFF) > OFFSET_SHORT_ITEM) { offset += 2; } else { offset += 1; } } return result; } }
|
RLP { public static byte[] decodeIP4Bytes(byte[] data, int index) { int offset = 1; final byte[] result = new byte[4]; for (int i = 0; i < 4; i++) { result[i] = decodeOneByteItem(data, index + offset); if ((data[index + offset] & 0xFF) > OFFSET_SHORT_ITEM) { offset += 2; } else { offset += 1; } } return result; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] decodeIP4Bytes(byte[] data, int index) { int offset = 1; final byte[] result = new byte[4]; for (int i = 0; i < 4; i++) { result[i] = decodeOneByteItem(data, index + offset); if ((data[index + offset] & 0xFF) > OFFSET_SHORT_ITEM) { offset += 2; } else { offset += 1; } } return result; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void cantLockOneOffAfterConsume() { Address randomAddress = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_REGTEST), "n3WzdjG7S2GjDbY1pJYxsY1VSQDkm4KDcm" ); OneOffWhiteListEntry entry = new OneOffWhiteListEntry(randomAddress, Coin.COIN); Assert.assertTrue(entry.canLock(Coin.COIN)); entry.consume(); Assert.assertFalse(entry.canLock(Coin.COIN)); }
|
public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
@Test public void canLockUnlimitedAfterConsume() { Address randomAddress = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_REGTEST), "n3WzdjG7S2GjDbY1pJYxsY1VSQDkm4KDcm" ); UnlimitedWhiteListEntry entry = new UnlimitedWhiteListEntry(randomAddress); Assert.assertTrue(entry.canLock(Coin.COIN)); entry.consume(); Assert.assertTrue(entry.canLock(Coin.COIN)); }
|
public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
LockWhitelist { public void consume(Address address) { LockWhitelistEntry entry = whitelistedAddresses.get(address); if (entry == null) { return; } entry.consume(); if (entry.isConsumed()) { this.remove(address); } } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
@Test public void getAllByType() { Assert.assertArrayEquals( addresses.values().stream().filter(e -> e.getClass() == OneOffWhiteListEntry.class).map(e-> e.address()).sorted().toArray(), whitelist.getAll(OneOffWhiteListEntry.class).stream().map(e-> e.address()).toArray() ); Assert.assertArrayEquals( addresses.values().stream().filter(e -> e.getClass() == UnlimitedWhiteListEntry.class).map(e-> e.address()).sorted().toArray(), whitelist.getAll(UnlimitedWhiteListEntry.class).stream().map(e-> e.address()).toArray() ); }
|
public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
@Test public void getAll() { Assert.assertEquals(addresses.size(), whitelist.getAll().size()); }
|
public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
LockWhitelist { public <T extends LockWhitelistEntry> List<T> getAll(Class<T> type) { return whitelistedAddresses.values().stream() .filter(e -> e.getClass() == type) .map(type::cast) .collect(Collectors.toList()); } LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses); LockWhitelist(Map<Address, LockWhitelistEntry> whitelistedAddresses, int disableBlockHeight); boolean isWhitelisted(Address address); boolean isWhitelisted(byte[] address); boolean isWhitelistedFor(Address address, Coin amount, int height); Integer getSize(); List<Address> getAddresses(); List<T> getAll(Class<T> type); List<LockWhitelistEntry> getAll(); LockWhitelistEntry get(Address address); boolean put(Address address, LockWhitelistEntry entry); boolean remove(Address address); void consume(Address address); int getDisableBlockHeight(); void setDisableBlockHeight(int disableBlockHeight); boolean isDisableBlockSet(); }
|
@Test public void getWitnessMerkleRoot() { Sha256Hash secondHashTx = Sha256Hash.wrap(Hex.decode("e3d0840a0825fb7d880e5cb8306745352920a8c7e8a30fac882b275e26c6bb65")); Sha256Hash witnessRoot = MerkleTreeUtils.combineLeftRight(Sha256Hash.ZERO_HASH, secondHashTx); CoinbaseInformation instance = new CoinbaseInformation(witnessRoot); Sha256Hash expectedHash = new Sha256Hash(Hex.decode("613cb22535df8d9443fe94b66d807cd60312f982e305e25e825b00e6f429799f")); Assert.assertEquals(expectedHash, instance.getWitnessMerkleRoot()); }
|
public Sha256Hash getWitnessMerkleRoot() { return witnessMerkleRoot; }
|
CoinbaseInformation { public Sha256Hash getWitnessMerkleRoot() { return witnessMerkleRoot; } }
|
CoinbaseInformation { public Sha256Hash getWitnessMerkleRoot() { return witnessMerkleRoot; } CoinbaseInformation(Sha256Hash witnessMerkleRoot); }
|
CoinbaseInformation { public Sha256Hash getWitnessMerkleRoot() { return witnessMerkleRoot; } CoinbaseInformation(Sha256Hash witnessMerkleRoot); Sha256Hash getWitnessMerkleRoot(); }
|
CoinbaseInformation { public Sha256Hash getWitnessMerkleRoot() { return witnessMerkleRoot; } CoinbaseInformation(Sha256Hash witnessMerkleRoot); Sha256Hash getWitnessMerkleRoot(); }
|
@Test public void getNewFederation_initialVersion() throws IOException { List<Integer> storageCalls = new ArrayList<>(); List<Integer> deserializeCalls = new ArrayList<>(); Federation newFederation = buildMockFederation(100, 200, 300); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("newFederationFormatVersion"), address); return new byte[0]; } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("newFederation"), address); return new byte[]{(byte) 0xaa}; } }); PowerMockito.when(BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(any(byte[].class), any(NetworkParameters.class))).then((InvocationOnMock invocation) -> { deserializeCalls.add(0); byte[] data = invocation.getArgument(0); NetworkParameters networkParameters = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); Assert.assertEquals(networkParameters, config.getNetworkConstants().getBridgeConstants().getBtcParams()); return newFederation; }); Assert.assertEquals(newFederation, storageProvider.getNewFederation()); Assert.assertEquals(newFederation, storageProvider.getNewFederation()); Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(1, deserializeCalls.size()); }
|
public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getNewFederation_initialVersion_nullBytes() throws IOException { List<Integer> storageCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("newFederationFormatVersion"), address); return new byte[0]; } else { Assert.assertTrue(storageCalls.size() == 2 || storageCalls.size() == 3); Assert.assertEquals(DataWord.fromString("newFederation"), address); return null; } }); Assert.assertEquals(null, storageProvider.getNewFederation()); Assert.assertEquals(null, storageProvider.getNewFederation()); Assert.assertEquals(3, storageCalls.size()); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(any(byte[].class), any(NetworkParameters.class)); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(NetworkParameters.class)); }
|
public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getNewFederation_multiKeyVersion() throws IOException { List<Integer> storageCalls = new ArrayList<>(); List<Integer> deserializeCalls = new ArrayList<>(); Federation newFederation = buildMockFederation(100, 200, 300); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("newFederationFormatVersion"), address); return RLP.encodeBigInteger(BigInteger.valueOf(1234)); } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("newFederation"), address); return new byte[]{(byte) 0xaa}; } }); PowerMockito.when(BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(NetworkParameters.class))).then((InvocationOnMock invocation) -> { deserializeCalls.add(0); byte[] data = invocation.getArgument(0); NetworkParameters networkParameters = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); Assert.assertEquals(networkParameters, config.getNetworkConstants().getBridgeConstants().getBtcParams()); return newFederation; }); Assert.assertEquals(newFederation, storageProvider.getNewFederation()); Assert.assertEquals(newFederation, storageProvider.getNewFederation()); Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(1, deserializeCalls.size()); }
|
public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getNewFederation_multiKeyVersion_nullBytes() throws IOException { List<Integer> storageCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("newFederationFormatVersion"), address); return RLP.encodeBigInteger(BigInteger.valueOf(1234)); } else { Assert.assertTrue(storageCalls.size() == 2 || storageCalls.size() == 3); Assert.assertEquals(DataWord.fromString("newFederation"), address); return null; } }); Assert.assertEquals(null, storageProvider.getNewFederation()); Assert.assertEquals(null, storageProvider.getNewFederation()); Assert.assertEquals(3, storageCalls.size()); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(any(byte[].class), any(NetworkParameters.class)); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(NetworkParameters.class)); }
|
public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getNewFederation() { if (newFederation != null) { return newFederation; } Optional<Integer> storageVersion = getStorageVersion(NEW_FEDERATION_FORMAT_VERSION); newFederation = safeGetFromRepository(NEW_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return newFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getOldFederation_initialVersion() throws IOException { List<Integer> storageCalls = new ArrayList<>(); List<Integer> deserializeCalls = new ArrayList<>(); Federation oldFederation = buildMockFederation(100, 200, 300); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("oldFederationFormatVersion"), address); return new byte[0]; } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("oldFederation"), address); return new byte[]{(byte) 0xaa}; } }); PowerMockito.when(BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(any(byte[].class), any(NetworkParameters.class))).then((InvocationOnMock invocation) -> { deserializeCalls.add(0); byte[] data = invocation.getArgument(0); NetworkParameters networkParameters = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); Assert.assertEquals(networkParameters, config.getNetworkConstants().getBridgeConstants().getBtcParams()); return oldFederation; }); Assert.assertEquals(oldFederation, storageProvider.getOldFederation()); Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(1, deserializeCalls.size()); }
|
public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void test2() throws UnknownHostException { String peersPacket = "F8 4E 11 F8 4B C5 36 81 " + "CC 0A 29 82 76 5F B8 40 D8 D6 0C 25 80 FA 79 5C " + "FC 03 13 EF DE BA 86 9D 21 94 E7 9E 7C B2 B5 22 " + "F7 82 FF A0 39 2C BB AB 8D 1B AC 30 12 08 B1 37 " + "E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " + "17 08 9F EA F8 4C 21 B0"; byte[] payload = Hex.decode(peersPacket); int oneInt = decodeInt(payload, 11); assertEquals(oneInt, 30303); }
|
public static int decodeInt(byte[] data, int index) { int value = 0; if ((data[index] & 0xFF) < OFFSET_SHORT_ITEM) { return data[index]; } else if ((data[index] & 0xFF) >= OFFSET_SHORT_ITEM && (data[index] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) (data[index] - OFFSET_SHORT_ITEM); byte pow = (byte) (length - 1); for (int i = 1; i <= length; ++i) { value += (data[index + i] & 0xFF) << (8 * pow); pow--; } } else { throw new RuntimeException("wrong decode attempt"); } return value; }
|
RLP { public static int decodeInt(byte[] data, int index) { int value = 0; if ((data[index] & 0xFF) < OFFSET_SHORT_ITEM) { return data[index]; } else if ((data[index] & 0xFF) >= OFFSET_SHORT_ITEM && (data[index] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) (data[index] - OFFSET_SHORT_ITEM); byte pow = (byte) (length - 1); for (int i = 1; i <= length; ++i) { value += (data[index + i] & 0xFF) << (8 * pow); pow--; } } else { throw new RuntimeException("wrong decode attempt"); } return value; } }
|
RLP { public static int decodeInt(byte[] data, int index) { int value = 0; if ((data[index] & 0xFF) < OFFSET_SHORT_ITEM) { return data[index]; } else if ((data[index] & 0xFF) >= OFFSET_SHORT_ITEM && (data[index] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) (data[index] - OFFSET_SHORT_ITEM); byte pow = (byte) (length - 1); for (int i = 1; i <= length; ++i) { value += (data[index + i] & 0xFF) << (8 * pow); pow--; } } else { throw new RuntimeException("wrong decode attempt"); } return value; } }
|
RLP { public static int decodeInt(byte[] data, int index) { int value = 0; if ((data[index] & 0xFF) < OFFSET_SHORT_ITEM) { return data[index]; } else if ((data[index] & 0xFF) >= OFFSET_SHORT_ITEM && (data[index] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) (data[index] - OFFSET_SHORT_ITEM); byte pow = (byte) (length - 1); for (int i = 1; i <= length; ++i) { value += (data[index + i] & 0xFF) << (8 * pow); pow--; } } else { throw new RuntimeException("wrong decode attempt"); } return value; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static int decodeInt(byte[] data, int index) { int value = 0; if ((data[index] & 0xFF) < OFFSET_SHORT_ITEM) { return data[index]; } else if ((data[index] & 0xFF) >= OFFSET_SHORT_ITEM && (data[index] & 0xFF) < OFFSET_LONG_ITEM) { byte length = (byte) (data[index] - OFFSET_SHORT_ITEM); byte pow = (byte) (length - 1); for (int i = 1; i <= length; ++i) { value += (data[index + i] & 0xFF) << (8 * pow); pow--; } } else { throw new RuntimeException("wrong decode attempt"); } return value; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void getOldFederation_initialVersion_nullBytes() throws IOException { List<Integer> storageCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("oldFederationFormatVersion"), address); return new byte[0]; } else { Assert.assertTrue(storageCalls.size() == 2 || storageCalls.size() == 3); Assert.assertEquals(DataWord.fromString("oldFederation"), address); return null; } }); Assert.assertEquals(null, storageProvider.getOldFederation()); Assert.assertEquals(null, storageProvider.getOldFederation()); Assert.assertEquals(3, storageCalls.size()); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(any(byte[].class), any(NetworkParameters.class)); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(NetworkParameters.class)); }
|
public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getOldFederation_multiKeyVersion() throws IOException { List<Integer> storageCalls = new ArrayList<>(); List<Integer> deserializeCalls = new ArrayList<>(); Federation oldFederation = buildMockFederation(100, 200, 300); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("oldFederationFormatVersion"), address); return RLP.encodeBigInteger(BigInteger.valueOf(1234)); } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("oldFederation"), address); return new byte[]{(byte) 0xaa}; } }); PowerMockito.when(BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(NetworkParameters.class))).then((InvocationOnMock invocation) -> { deserializeCalls.add(0); byte[] data = invocation.getArgument(0); NetworkParameters networkParameters = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); Assert.assertEquals(networkParameters, config.getNetworkConstants().getBridgeConstants().getBtcParams()); return oldFederation; }); Assert.assertEquals(oldFederation, storageProvider.getOldFederation()); Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(1, deserializeCalls.size()); }
|
public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getOldFederation_multiKeyVersion_nullBytes() throws IOException { List<Integer> storageCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("oldFederationFormatVersion"), address); return RLP.encodeBigInteger(BigInteger.valueOf(1234)); } else { Assert.assertTrue(storageCalls.size() == 2 || storageCalls.size() == 3); Assert.assertEquals(DataWord.fromString("oldFederation"), address); return null; } }); Assert.assertEquals(null, storageProvider.getOldFederation()); Assert.assertEquals(null, storageProvider.getOldFederation()); Assert.assertEquals(3, storageCalls.size()); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederationOnlyBtcKeys(any(byte[].class), any(NetworkParameters.class)); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializeFederation(any(byte[].class), any(NetworkParameters.class)); }
|
public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Federation getOldFederation() { if (oldFederation != null || shouldSaveOldFederation) { return oldFederation; } Optional<Integer> storageVersion = getStorageVersion(OLD_FEDERATION_FORMAT_VERSION); oldFederation = safeGetFromRepository(OLD_FEDERATION_KEY, data -> data == null ? null : deserializeFederationAccordingToVersion(data, storageVersion) ); return oldFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getPendingFederation_initialVersion() throws IOException { List<Integer> storageCalls = new ArrayList<>(); List<Integer> deserializeCalls = new ArrayList<>(); PendingFederation pendingFederation = buildMockPendingFederation(100, 200, 300); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("pendingFederationFormatVersion"), address); return new byte[0]; } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("pendingFederation"), address); return new byte[]{(byte) 0xaa}; } }); PowerMockito.when(BridgeSerializationUtils.deserializePendingFederationOnlyBtcKeys(any(byte[].class))).then((InvocationOnMock invocation) -> { deserializeCalls.add(0); byte[] data = invocation.getArgument(0); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); return pendingFederation; }); Assert.assertEquals(pendingFederation, storageProvider.getPendingFederation()); Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(1, deserializeCalls.size()); }
|
public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getPendingFederation_initialVersion_nullBytes() throws IOException { List<Integer> storageCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("pendingFederationFormatVersion"), address); return new byte[0]; } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("pendingFederation"), address); return null; } }); Assert.assertEquals(null, storageProvider.getPendingFederation()); Assert.assertEquals(2, storageCalls.size()); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializePendingFederation(any(byte[].class)); }
|
public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getPendingFederation_multiKeyVersion() throws IOException { List<Integer> storageCalls = new ArrayList<>(); List<Integer> deserializeCalls = new ArrayList<>(); PendingFederation pendingFederation = buildMockPendingFederation(100, 200, 300); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("pendingFederationFormatVersion"), address); return RLP.encodeBigInteger(BigInteger.valueOf(1234)); } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("pendingFederation"), address); return new byte[]{(byte) 0xaa}; } }); PowerMockito.when(BridgeSerializationUtils.deserializePendingFederation(any(byte[].class))).then((InvocationOnMock invocation) -> { deserializeCalls.add(0); byte[] data = invocation.getArgument(0); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); return pendingFederation; }); Assert.assertEquals(pendingFederation, storageProvider.getPendingFederation()); Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(1, deserializeCalls.size()); }
|
public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getPendingFederation_multiKeyVersion_nullBytes() throws IOException { List<Integer> storageCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { storageCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); if (storageCalls.size() == 1) { Assert.assertEquals(DataWord.fromString("pendingFederationFormatVersion"), address); return RLP.encodeBigInteger(BigInteger.valueOf(1234)); } else { Assert.assertEquals(2, storageCalls.size()); Assert.assertEquals(DataWord.fromString("pendingFederation"), address); return null; } }); Assert.assertEquals(null, storageProvider.getPendingFederation()); Assert.assertEquals(2, storageCalls.size()); PowerMockito.verifyStatic(never()); BridgeSerializationUtils.deserializePendingFederation(any(byte[].class)); }
|
public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public PendingFederation getPendingFederation() { if (pendingFederation != null || shouldSavePendingFederation) { return pendingFederation; } Optional<Integer> storageVersion = getStorageVersion(PENDING_FEDERATION_FORMAT_VERSION); pendingFederation = safeGetFromRepository(PENDING_FEDERATION_KEY, data -> data == null ? null : deserializePendingFederationAccordingToVersion(data, storageVersion) ); return pendingFederation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getFederationElection_nonNullBytes() throws IOException { List<Integer> calls = new ArrayList<>(); AddressBasedAuthorizer authorizerMock = mock(AddressBasedAuthorizer.class); ABICallElection electionMock = mock(ABICallElection.class); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { calls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xbb, (byte)0xcc, (byte)0xdd}, contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("federationElection".getBytes(StandardCharsets.UTF_8)), address); return new byte[]{(byte)0xaa}; }); PowerMockito.when(BridgeSerializationUtils.deserializeElection(any(byte[].class), any(AddressBasedAuthorizer.class))).then((InvocationOnMock invocation) -> { calls.add(0); byte[] data = invocation.getArgument(0); AddressBasedAuthorizer authorizer = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); Assert.assertEquals(authorizerMock, authorizer); return electionMock; }); Assert.assertSame(electionMock, storageProvider.getFederationElection(authorizerMock)); Assert.assertEquals(2, calls.size()); }
|
public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getFederationElection_nullBytes() throws IOException { List<Integer> calls = new ArrayList<>(); AddressBasedAuthorizer authorizerMock = mock(AddressBasedAuthorizer.class); ABICallElection electionMock = mock(ABICallElection.class); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))).then((InvocationOnMock invocation) -> { calls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xbb, (byte)0xcc, (byte)0xdd}, contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("federationElection".getBytes(StandardCharsets.UTF_8)), address); return null; }); PowerMockito.when(BridgeSerializationUtils.deserializeElection(any(byte[].class), any(AddressBasedAuthorizer.class))).then((InvocationOnMock invocation) -> { calls.add(0); return null; }); ABICallElection result = storageProvider.getFederationElection(authorizerMock); Assert.assertSame(authorizerMock, Whitebox.getInternalState(result, "authorizer")); Assert.assertEquals(0, result.getVotes().size()); Assert.assertEquals(1, calls.size()); }
|
public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ABICallElection getFederationElection(AddressBasedAuthorizer authorizer) { if (federationElection != null) { return federationElection; } federationElection = safeGetFromRepository(FEDERATION_ELECTION_KEY, data -> (data == null)? new ABICallElection(authorizer) : BridgeSerializationUtils.deserializeElection(data, authorizer)); return federationElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void saveFederationElection() throws IOException { ABICallElection electionMock = mock(ABICallElection.class); List<Integer> storageBytesCalls = new ArrayList<>(); List<Integer> serializeCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); PowerMockito.when(BridgeSerializationUtils.serializeElection(any(ABICallElection.class))).then((InvocationOnMock invocation) -> { ABICallElection election = invocation.getArgument(0); Assert.assertSame(electionMock, election); serializeCalls.add(0); return Hex.decode("aabb"); }); Mockito.doAnswer((InvocationOnMock invocation) -> { storageBytesCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); byte[] data = invocation.getArgument(2); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xbb, (byte)0xcc, (byte)0xdd}, contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("federationElection".getBytes(StandardCharsets.UTF_8)), address); Assert.assertTrue(Arrays.equals(Hex.decode("aabb"), data)); return null; }).when(repositoryMock).addStorageBytes(any(RskAddress.class), any(DataWord.class), any(byte[].class)); storageProvider.saveFederationElection(); Assert.assertEquals(0, storageBytesCalls.size()); Assert.assertEquals(0, serializeCalls.size()); Whitebox.setInternalState(storageProvider, "federationElection", electionMock); storageProvider.saveFederationElection(); Assert.assertEquals(1, storageBytesCalls.size()); Assert.assertEquals(1, serializeCalls.size()); }
|
public void saveFederationElection() { if (federationElection == null) { return; } safeSaveToRepository(FEDERATION_ELECTION_KEY, federationElection, BridgeSerializationUtils::serializeElection); }
|
BridgeStorageProvider { public void saveFederationElection() { if (federationElection == null) { return; } safeSaveToRepository(FEDERATION_ELECTION_KEY, federationElection, BridgeSerializationUtils::serializeElection); } }
|
BridgeStorageProvider { public void saveFederationElection() { if (federationElection == null) { return; } safeSaveToRepository(FEDERATION_ELECTION_KEY, federationElection, BridgeSerializationUtils::serializeElection); } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public void saveFederationElection() { if (federationElection == null) { return; } safeSaveToRepository(FEDERATION_ELECTION_KEY, federationElection, BridgeSerializationUtils::serializeElection); } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public void saveFederationElection() { if (federationElection == null) { return; } safeSaveToRepository(FEDERATION_ELECTION_KEY, federationElection, BridgeSerializationUtils::serializeElection); } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void test4() { byte[] expected = {(byte) 0x80}; byte[] data = encodeByte((byte) 0); assertArrayEquals(expected, data); byte[] expected2 = {(byte) 0x78}; data = encodeByte((byte) 120); assertArrayEquals(expected2, data); byte[] expected3 = {(byte) 0x7F}; data = encodeByte((byte) 127); assertArrayEquals(expected3, data); }
|
public static byte[] encodeByte(byte singleByte) { if ((singleByte & 0xFF) == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if ((singleByte & 0xFF) <= 0x7F) { return new byte[]{singleByte}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 1), singleByte}; } }
|
RLP { public static byte[] encodeByte(byte singleByte) { if ((singleByte & 0xFF) == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if ((singleByte & 0xFF) <= 0x7F) { return new byte[]{singleByte}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 1), singleByte}; } } }
|
RLP { public static byte[] encodeByte(byte singleByte) { if ((singleByte & 0xFF) == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if ((singleByte & 0xFF) <= 0x7F) { return new byte[]{singleByte}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 1), singleByte}; } } }
|
RLP { public static byte[] encodeByte(byte singleByte) { if ((singleByte & 0xFF) == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if ((singleByte & 0xFF) <= 0x7F) { return new byte[]{singleByte}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 1), singleByte}; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeByte(byte singleByte) { if ((singleByte & 0xFF) == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if ((singleByte & 0xFF) <= 0x7F) { return new byte[]{singleByte}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 1), singleByte}; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void getLockWhitelist_nonNullBytes() { List<Integer> calls = new ArrayList<>(); LockWhitelist whitelistMock = new LockWhitelist(new HashMap<>()); LockWhitelistEntry oneOffEntry = new OneOffWhiteListEntry(getBtcAddress("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), Coin.COIN); LockWhitelistEntry unlimitedEntry = new UnlimitedWhiteListEntry(getBtcAddress("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")); whitelistMock.put(oneOffEntry.address(), oneOffEntry); whitelistMock.put(unlimitedEntry.address(), unlimitedEntry); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsAllForks); when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.valueOf("lockWhitelist".getBytes(StandardCharsets.UTF_8))))) .then((InvocationOnMock invocation) -> { calls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xbb, (byte)0xcc, (byte)0xdd}, contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("lockWhitelist".getBytes(StandardCharsets.UTF_8)), address); return new byte[]{(byte)0xaa}; }); when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.valueOf("unlimitedLockWhitelist".getBytes(StandardCharsets.UTF_8))))) .then((InvocationOnMock invocation) -> { calls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xbb, (byte)0xcc, (byte)0xdd}, contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("unlimitedLockWhitelist".getBytes(StandardCharsets.UTF_8)), address); return new byte[]{(byte)0xbb}; }); PowerMockito .when(BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(any(byte[].class), any(NetworkParameters.class))) .then((InvocationOnMock invocation) -> { calls.add(0); byte[] data = invocation.getArgument(0); NetworkParameters parameters = invocation.getArgument(1); Assert.assertEquals(NetworkParameters.fromID(NetworkParameters.ID_REGTEST), parameters); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa}, data)); HashMap<Address, LockWhitelistEntry> map = new HashMap<>(); map.put(oneOffEntry.address(), oneOffEntry); return Pair.of(map, 0); }); PowerMockito .when(BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(any(byte[].class), any(NetworkParameters.class))) .then((InvocationOnMock invocation) -> { calls.add(0); byte[] unlimitedData = invocation.getArgument(0); NetworkParameters parameters = invocation.getArgument(1); Assert.assertEquals(NetworkParameters.fromID(NetworkParameters.ID_REGTEST), parameters); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xbb}, unlimitedData)); HashMap<Address, LockWhitelistEntry> map = new HashMap<>(); map.put(unlimitedEntry.address(), unlimitedEntry); return map; }); Assert.assertEquals(whitelistMock.getAll(), storageProvider.getLockWhitelist().getAll()); Assert.assertEquals(4, calls.size()); }
|
public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getLockWhitelist_nullBytes() { List<Integer> calls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsAllForks); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))) .then((InvocationOnMock invocation) -> { calls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); Assert.assertTrue(Arrays.equals(new byte[]{(byte)0xaa, (byte)0xbb, (byte)0xcc, (byte)0xdd}, contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("lockWhitelist".getBytes(StandardCharsets.UTF_8)), address); return new byte[]{(byte)0xee}; }); PowerMockito .when(BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(any(byte[].class), any(NetworkParameters.class))) .then((InvocationOnMock invocation) -> { calls.add(0); return null; }); PowerMockito .when(BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(any(byte[].class), any(NetworkParameters.class))) .then((InvocationOnMock invocation) -> { calls.add(0); Assert.fail("As we don't have data for one-off, we shouldn't have called deserialize unlimited"); return null; }); LockWhitelist result = storageProvider.getLockWhitelist(); Assert.assertNotNull(result); Assert.assertEquals(0, result.getSize().intValue()); Assert.assertEquals(2, calls.size()); }
|
public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public LockWhitelist getLockWhitelist() { if (lockWhitelist != null) { return lockWhitelist; } Pair<HashMap<Address, OneOffWhiteListEntry>, Integer> oneOffWhitelistAndDisableBlockHeightData = safeGetFromRepository(LOCK_ONE_OFF_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeOneOffLockWhitelistAndDisableBlockHeight(data, networkParameters)); if (oneOffWhitelistAndDisableBlockHeightData == null) { lockWhitelist = new LockWhitelist(new HashMap<>()); return lockWhitelist; } Map<Address, LockWhitelistEntry> whitelistedAddresses = new HashMap<>(); whitelistedAddresses.putAll(oneOffWhitelistAndDisableBlockHeightData.getLeft()); if (activations.isActive(RSKIP87)) { whitelistedAddresses.putAll(safeGetFromRepository(LOCK_UNLIMITED_WHITELIST_KEY, data -> BridgeSerializationUtils.deserializeUnlimitedLockWhitelistEntries(data, networkParameters))); } lockWhitelist = new LockWhitelist(whitelistedAddresses, oneOffWhitelistAndDisableBlockHeightData.getRight()); return lockWhitelist; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void saveLockWhitelist() { LockWhitelist whitelistMock = mock(LockWhitelist.class); List<Integer> storageBytesCalls = new ArrayList<>(); List<Integer> serializeCalls = new ArrayList<>(); PowerMockito.mockStatic(BridgeSerializationUtils.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsAllForks); PowerMockito .when(BridgeSerializationUtils.serializeOneOffLockWhitelist(any(Pair.class))) .then((InvocationOnMock invocation) -> { Pair<List<OneOffWhiteListEntry>, Integer> data = invocation.getArgument(0); Assert.assertEquals(whitelistMock.getAll(OneOffWhiteListEntry.class), data.getLeft()); Assert.assertSame(whitelistMock.getDisableBlockHeight(), data.getRight()); serializeCalls.add(0); return Hex.decode("ccdd"); }); Mockito .doAnswer((InvocationOnMock invocation) -> { storageBytesCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); byte[] data = invocation.getArgument(2); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("lockWhitelist".getBytes(StandardCharsets.UTF_8)), address); Assert.assertTrue(Arrays.equals(Hex.decode("ccdd"), data)); return null; }) .when(repositoryMock).addStorageBytes(any(RskAddress.class), eq(DataWord.valueOf("lockWhitelist".getBytes(StandardCharsets.UTF_8))), any(byte[].class)); PowerMockito .when(BridgeSerializationUtils.serializeUnlimitedLockWhitelist(any(List.class))) .then((InvocationOnMock invocation) -> { List<UnlimitedWhiteListEntry> unlimitedWhiteListEntries = invocation.getArgument(0); Assert.assertEquals(whitelistMock.getAll(UnlimitedWhiteListEntry.class), unlimitedWhiteListEntries); serializeCalls.add(0); return Hex.decode("bbcc"); }); Mockito .doAnswer((InvocationOnMock invocation) -> { storageBytesCalls.add(0); RskAddress contractAddress = invocation.getArgument(0); DataWord address = invocation.getArgument(1); byte[] data = invocation.getArgument(2); Assert.assertTrue(Arrays.equals(Hex.decode("aabbccdd"), contractAddress.getBytes())); Assert.assertEquals(DataWord.valueOf("unlimitedLockWhitelist".getBytes(StandardCharsets.UTF_8)), address); Assert.assertTrue(Arrays.equals(Hex.decode("bbcc"), data)); return null; }) .when(repositoryMock).addStorageBytes(any(RskAddress.class), eq(DataWord.valueOf("unlimitedLockWhitelist".getBytes(StandardCharsets.UTF_8))), any(byte[].class)); storageProvider.saveLockWhitelist(); Assert.assertEquals(0, storageBytesCalls.size()); Assert.assertEquals(0, serializeCalls.size()); Whitebox.setInternalState(storageProvider, "lockWhitelist", whitelistMock); storageProvider.saveLockWhitelist(); Assert.assertEquals(2, storageBytesCalls.size()); Assert.assertEquals(2, serializeCalls.size()); }
|
public void saveLockWhitelist() { if (lockWhitelist == null) { return; } List<OneOffWhiteListEntry> oneOffEntries = lockWhitelist.getAll(OneOffWhiteListEntry.class); safeSaveToRepository(LOCK_ONE_OFF_WHITELIST_KEY, Pair.of(oneOffEntries, lockWhitelist.getDisableBlockHeight()), BridgeSerializationUtils::serializeOneOffLockWhitelist); if (activations.isActive(RSKIP87)) { List<UnlimitedWhiteListEntry> unlimitedEntries = lockWhitelist.getAll(UnlimitedWhiteListEntry.class); safeSaveToRepository(LOCK_UNLIMITED_WHITELIST_KEY, unlimitedEntries, BridgeSerializationUtils::serializeUnlimitedLockWhitelist); } }
|
BridgeStorageProvider { public void saveLockWhitelist() { if (lockWhitelist == null) { return; } List<OneOffWhiteListEntry> oneOffEntries = lockWhitelist.getAll(OneOffWhiteListEntry.class); safeSaveToRepository(LOCK_ONE_OFF_WHITELIST_KEY, Pair.of(oneOffEntries, lockWhitelist.getDisableBlockHeight()), BridgeSerializationUtils::serializeOneOffLockWhitelist); if (activations.isActive(RSKIP87)) { List<UnlimitedWhiteListEntry> unlimitedEntries = lockWhitelist.getAll(UnlimitedWhiteListEntry.class); safeSaveToRepository(LOCK_UNLIMITED_WHITELIST_KEY, unlimitedEntries, BridgeSerializationUtils::serializeUnlimitedLockWhitelist); } } }
|
BridgeStorageProvider { public void saveLockWhitelist() { if (lockWhitelist == null) { return; } List<OneOffWhiteListEntry> oneOffEntries = lockWhitelist.getAll(OneOffWhiteListEntry.class); safeSaveToRepository(LOCK_ONE_OFF_WHITELIST_KEY, Pair.of(oneOffEntries, lockWhitelist.getDisableBlockHeight()), BridgeSerializationUtils::serializeOneOffLockWhitelist); if (activations.isActive(RSKIP87)) { List<UnlimitedWhiteListEntry> unlimitedEntries = lockWhitelist.getAll(UnlimitedWhiteListEntry.class); safeSaveToRepository(LOCK_UNLIMITED_WHITELIST_KEY, unlimitedEntries, BridgeSerializationUtils::serializeUnlimitedLockWhitelist); } } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public void saveLockWhitelist() { if (lockWhitelist == null) { return; } List<OneOffWhiteListEntry> oneOffEntries = lockWhitelist.getAll(OneOffWhiteListEntry.class); safeSaveToRepository(LOCK_ONE_OFF_WHITELIST_KEY, Pair.of(oneOffEntries, lockWhitelist.getDisableBlockHeight()), BridgeSerializationUtils::serializeOneOffLockWhitelist); if (activations.isActive(RSKIP87)) { List<UnlimitedWhiteListEntry> unlimitedEntries = lockWhitelist.getAll(UnlimitedWhiteListEntry.class); safeSaveToRepository(LOCK_UNLIMITED_WHITELIST_KEY, unlimitedEntries, BridgeSerializationUtils::serializeUnlimitedLockWhitelist); } } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public void saveLockWhitelist() { if (lockWhitelist == null) { return; } List<OneOffWhiteListEntry> oneOffEntries = lockWhitelist.getAll(OneOffWhiteListEntry.class); safeSaveToRepository(LOCK_ONE_OFF_WHITELIST_KEY, Pair.of(oneOffEntries, lockWhitelist.getDisableBlockHeight()), BridgeSerializationUtils::serializeOneOffLockWhitelist); if (activations.isActive(RSKIP87)) { List<UnlimitedWhiteListEntry> unlimitedEntries = lockWhitelist.getAll(UnlimitedWhiteListEntry.class); safeSaveToRepository(LOCK_UNLIMITED_WHITELIST_KEY, unlimitedEntries, BridgeSerializationUtils::serializeUnlimitedLockWhitelist); } } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getReleaseRequestQueue_before_rskip_146_activation() throws IOException { Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); List<ReleaseRequestQueue.Entry> oldEntriesList = new ArrayList<>(Collections.singletonList( new ReleaseRequestQueue.Entry( Address.fromBase58(BridgeRegTestConstants.getInstance().getBtcParams(), "mmWJhA74Pd6peL39V3AmtGHdGdJ4PyeXvL"), Coin.COIN))); when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseRequestQueue")))) .then((InvocationOnMock invocation) -> BridgeSerializationUtils.serializeReleaseRequestQueue(new ReleaseRequestQueue(oldEntriesList))); ReleaseRequestQueue result = storageProvider.getReleaseRequestQueue(); verify(repositoryMock, never()).getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseRequestQueueWithTxHash"))); Assert.assertEquals(1, result.getEntries().size()); Assert.assertTrue(result.getEntries().containsAll(oldEntriesList)); }
|
public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getReleaseRequestQueue_after_rskip_146_activation() throws IOException { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true); ReleaseRequestQueue.Entry oldEntry = new ReleaseRequestQueue.Entry( Address.fromBase58(BridgeRegTestConstants.getInstance().getBtcParams(), "mmWJhA74Pd6peL39V3AmtGHdGdJ4PyeXvL"), Coin.COIN); ReleaseRequestQueue.Entry newEntry = new ReleaseRequestQueue.Entry( Address.fromBase58(BridgeRegTestConstants.getInstance().getBtcParams(), "mseEsMLuzaEdGbyAv9c9VRL9qGcb49qnxB"), Coin.COIN, PegTestUtils.createHash3(0) ); Repository repositoryMock = mock(Repository.class); when(repositoryMock.getStorageBytes(any(),eq(DataWord.fromString("releaseRequestQueue")))). thenReturn(BridgeSerializationUtils.serializeReleaseRequestQueue(new ReleaseRequestQueue(new ArrayList<>(Arrays.asList(oldEntry))))); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activations); ReleaseRequestQueue releaseRequestQueue = storageProvider.getReleaseRequestQueue(); releaseRequestQueue.add(Address.fromBase58(BridgeRegTestConstants.getInstance().getBtcParams(), "mseEsMLuzaEdGbyAv9c9VRL9qGcb49qnxB"), Coin.COIN, PegTestUtils.createHash3(0)); when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseRequestQueueWithTxHash")))) .then((InvocationOnMock invocation) -> BridgeSerializationUtils.serializeReleaseRequestQueueWithTxHash(new ReleaseRequestQueue(new ArrayList<>(Collections.singletonList(newEntry))))); ReleaseRequestQueue result = storageProvider.getReleaseRequestQueue(); Assert.assertEquals(2, result.getEntries().size()); Assert.assertEquals(result.getEntries().get(0), oldEntry); Assert.assertEquals(result.getEntries().get(1), newEntry); }
|
public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ReleaseRequestQueue getReleaseRequestQueue() throws IOException { if (releaseRequestQueue != null) { return releaseRequestQueue; } List<ReleaseRequestQueue.Entry> entries = new ArrayList<>(); entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters) ) ); if (!activations.isActive(RSKIP146)) { releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } entries.addAll(getFromRepository( RELEASE_REQUEST_QUEUE_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseRequestQueue(data, networkParameters, true) ) ); releaseRequestQueue = new ReleaseRequestQueue(entries); return releaseRequestQueue; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getReleaseTransactionSet_before_rskip_146_activation() throws IOException { Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); Set<ReleaseTransactionSet.Entry> oldEntriesSet = new HashSet<>(Collections.singletonList( new ReleaseTransactionSet.Entry(new BtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams()), 1L) )); when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSet")))) .then((InvocationOnMock invocation) -> BridgeSerializationUtils.serializeReleaseTransactionSet(new ReleaseTransactionSet(oldEntriesSet))); ReleaseTransactionSet result = storageProvider.getReleaseTransactionSet(); verify(repositoryMock, never()).getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSetWithTxHash"))); Assert.assertEquals(1, result.getEntries().size()); Assert.assertTrue(result.getEntries().containsAll(oldEntriesSet)); }
|
public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getReleaseTransactionSet_after_rskip_146_activation() throws IOException { ActivationConfig.ForBlock activations = mock(ActivationConfig.ForBlock.class); when(activations.isActive(ConsensusRule.RSKIP146)).thenReturn(true); Set<ReleaseTransactionSet.Entry> oldEntriesSet = new HashSet<>(Collections.singletonList( new ReleaseTransactionSet.Entry(new BtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams()), 1L) )); Set<ReleaseTransactionSet.Entry> newEntriesSet = new HashSet<>(Collections.singletonList( new ReleaseTransactionSet.Entry(new BtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams()), 1L, PegTestUtils.createHash3(0) ))); Repository repositoryMock = mock(Repository.class); when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSet")))) .thenReturn(BridgeSerializationUtils.serializeReleaseTransactionSet(new ReleaseTransactionSet(oldEntriesSet))); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activations); ReleaseTransactionSet releaseTransactionSet = storageProvider.getReleaseTransactionSet(); releaseTransactionSet.add(new SimpleBtcTransaction(config.getNetworkConstants().getBridgeConstants().getBtcParams(), PegTestUtils.createHash(0)), 1L, PegTestUtils.createHash3(0)); when(repositoryMock.getStorageBytes(any(RskAddress.class), eq(DataWord.fromString("releaseTransactionSetWithTxHash")))) .then((InvocationOnMock invocation) -> BridgeSerializationUtils.serializeReleaseTransactionSetWithTxHash(new ReleaseTransactionSet(newEntriesSet))); ReleaseTransactionSet result = storageProvider.getReleaseTransactionSet(); Assert.assertEquals(2, result.getEntries().size()); }
|
public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ReleaseTransactionSet getReleaseTransactionSet() throws IOException { if (releaseTransactionSet != null) { return releaseTransactionSet; } Set<ReleaseTransactionSet.Entry> entries = new HashSet<>(getFromRepository(RELEASE_TX_SET, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters).getEntries())); if (!activations.isActive(RSKIP146)) { releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } entries.addAll(getFromRepository( RELEASE_TX_SET_WITH_TXHASH, data -> BridgeSerializationUtils.deserializeReleaseTransactionSet(data, networkParameters, true).getEntries())); releaseTransactionSet = new ReleaseTransactionSet(entries); return releaseTransactionSet; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getFeePerKbElection_emptyVotes() { AddressBasedAuthorizer authorizerMock = mock(AddressBasedAuthorizer.class); Repository repositoryMock = mock(Repository.class); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); HashMap<ABICallSpec, List<RskAddress>> electionVotes = new HashMap<>(); byte[] serializedElection = BridgeSerializationUtils.serializeElection( new ABICallElection(authorizerMock, electionVotes)); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))) .thenReturn(serializedElection); when(authorizerMock.getRequiredAuthorizedKeys()) .thenReturn(1); ABICallElection result = storageProvider.getFeePerKbElection(authorizerMock); assertThat(result.getVotes().isEmpty(), is(true)); assertThat(result.getWinner(), nullValue()); }
|
public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getFeePerKbElection_withVotes() { AddressBasedAuthorizer authorizerMock = mock(AddressBasedAuthorizer.class); Repository repositoryMock = mock(Repository.class); when(authorizerMock.getRequiredAuthorizedKeys()) .thenReturn(1); when(authorizerMock.isAuthorized(any(RskAddress.class))) .thenReturn(true); BridgeStorageProvider storageProvider = new BridgeStorageProvider(repositoryMock, mockAddress("aabbccdd"), config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork); byte[] electionFee = new byte[] {0x43, 0x19}; ABICallSpec expectedWinner = new ABICallSpec("setFeePerKb", new byte[][]{electionFee}); List<RskAddress> voters = new ArrayList<>(); voters.add(new RskAddress("0000000000000000000000000000000000001321")); voters.add(new RskAddress("0000000000000000000000000000000000004049")); HashMap<ABICallSpec, List<RskAddress>> electionVotes = new HashMap<>(); electionVotes.put(expectedWinner, voters); byte[] serializedElection = BridgeSerializationUtils.serializeElection( new ABICallElection(authorizerMock, electionVotes)); when(repositoryMock.getStorageBytes(any(RskAddress.class), any(DataWord.class))) .thenReturn(serializedElection); ABICallElection result = storageProvider.getFeePerKbElection(authorizerMock); assertThat(result.getVotes(), is(electionVotes)); assertThat(result.getWinner(), is(expectedWinner)); }
|
public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer) { if (feePerKbElection != null) { return feePerKbElection; } feePerKbElection = safeGetFromRepository(FEE_PER_KB_ELECTION_KEY, data -> BridgeSerializationUtils.deserializeElection(data, authorizer)); return feePerKbElection; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getLockingCap_before_fork() { Repository repository = mock(Repository.class); when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("lockingCap"))).thenReturn(new byte[] { 1 }); BridgeStorageProvider provider0 = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork ); assertNull(provider0.getLockingCap()); verify(repository, never()).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("lockingCap")); }
|
public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void test5() { byte[] expected = {(byte) 0x80}; byte[] data = encodeShort((byte) 0); assertArrayEquals(expected, data); byte[] expected2 = {(byte) 0x78}; data = encodeShort((byte) 120); assertArrayEquals(expected2, data); byte[] expected3 = { (byte) 0x7F}; data = encodeShort((byte) 127); assertArrayEquals(expected3, data); byte[] expected4 = {(byte) 0x82, (byte) 0x76, (byte) 0x5F}; data = encodeShort((short) 30303); assertArrayEquals(expected4, data); byte[] expected5 = {(byte) 0x82, (byte) 0x4E, (byte) 0xEA}; data = encodeShort((short) 20202); assertArrayEquals(expected5, data); byte[] expected6 = {(byte) 0x82, (byte) 0x9D, (byte) 0x0A}; data = encodeShort((short) 40202); assertArrayEquals(expected6, data); }
|
public static byte[] encodeShort(short singleShort) { if ((singleShort & 0xFF) == singleShort) { return encodeByte((byte) singleShort); } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 2), (byte) (singleShort >> 8 & 0xFF), (byte) (singleShort >> 0 & 0xFF)}; } }
|
RLP { public static byte[] encodeShort(short singleShort) { if ((singleShort & 0xFF) == singleShort) { return encodeByte((byte) singleShort); } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 2), (byte) (singleShort >> 8 & 0xFF), (byte) (singleShort >> 0 & 0xFF)}; } } }
|
RLP { public static byte[] encodeShort(short singleShort) { if ((singleShort & 0xFF) == singleShort) { return encodeByte((byte) singleShort); } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 2), (byte) (singleShort >> 8 & 0xFF), (byte) (singleShort >> 0 & 0xFF)}; } } }
|
RLP { public static byte[] encodeShort(short singleShort) { if ((singleShort & 0xFF) == singleShort) { return encodeByte((byte) singleShort); } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 2), (byte) (singleShort >> 8 & 0xFF), (byte) (singleShort >> 0 & 0xFF)}; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeShort(short singleShort) { if ((singleShort & 0xFF) == singleShort) { return encodeByte((byte) singleShort); } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 2), (byte) (singleShort >> 8 & 0xFF), (byte) (singleShort >> 0 & 0xFF)}; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void getLockingCap_after_fork() { Repository repository = mock(Repository.class); when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("lockingCap"))).thenReturn(new byte[] { 1 }); BridgeStorageProvider provider0 = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks ); assertEquals(Coin.SATOSHI, provider0.getLockingCap()); verify(repository, atLeastOnce()).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("lockingCap")); }
|
public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Coin getLockingCap() { if (activations.isActive(RSKIP134)) { if (this.lockingCap == null) { this.lockingCap = safeGetFromRepository(LOCKING_CAP_KEY, BridgeSerializationUtils::deserializeCoin); } return this.lockingCap; } return null; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getHeightIfBtcTxhashIsAlreadyProcessed_before_RSKIP134_does_not_use_new_storage() throws IOException { Repository repository = mock(Repository.class); Sha256Hash hash = Sha256Hash.ZERO_HASH; HashMap<Sha256Hash, Long> hashes = new HashMap<>(); hashes.put(hash, 1L); when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("btcTxHashesAP"))) .thenReturn(BridgeSerializationUtils.serializeMapOfHashesToLong(hashes)); BridgeStorageProvider provider0 = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork ); Optional<Long> result = provider0.getHeightIfBtcTxhashIsAlreadyProcessed(hash); assertTrue(result.isPresent()); assertEquals(Long.valueOf(1), result.get()); verify(repository, times(1)).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("btcTxHashesAP")); verify(repository, never()).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("btcTxHashAP-" + hash.toString())); }
|
public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getHeightIfBtcTxhashIsAlreadyProcessed_after_RSKIP134_uses_new_storage() throws IOException { Repository repository = mock(Repository.class); Sha256Hash hash1 = Sha256Hash.ZERO_HASH; Sha256Hash hash2 = Sha256Hash.wrap("0000000000000000000000000000000000000000000000000000000000000001"); HashMap<Sha256Hash, Long> hashes = new HashMap<>(); hashes.put(hash1, 1L); when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("btcTxHashesAP"))) .thenReturn(BridgeSerializationUtils.serializeMapOfHashesToLong(hashes)); when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("btcTxHashAP-" + hash2.toString()))) .thenReturn(BridgeSerializationUtils.serializeLong(2L)); BridgeStorageProvider provider0 = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks ); Optional<Long> result = provider0.getHeightIfBtcTxhashIsAlreadyProcessed(hash1); assertTrue(result.isPresent()); assertEquals(Long.valueOf(1), result.get()); verify(repository, times(1)).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("btcTxHashesAP")); verify(repository, never()).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("btcTxHashAP-" + hash2.toString())); result = provider0.getHeightIfBtcTxhashIsAlreadyProcessed(hash2); assertTrue(result.isPresent()); assertEquals(Long.valueOf(2), result.get()); verify(repository, times(1)).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("btcTxHashesAP")); verify(repository, times(1)).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("btcTxHashAP-" + hash2.toString())); result = provider0.getHeightIfBtcTxhashIsAlreadyProcessed(hash2); assertTrue(result.isPresent()); assertEquals(Long.valueOf(2), result.get()); verify(repository, times(1)).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("btcTxHashesAP")); verify(repository, times(1)).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("btcTxHashAP-" + hash2.toString())); }
|
public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash) throws IOException { Map<Sha256Hash, Long> processed = getBtcTxHashesAlreadyProcessed(); if (processed.containsKey(btcTxHash)) { return Optional.of(processed.get(btcTxHash)); } if (!activations.isActive(RSKIP134)) { return Optional.empty(); } if (btcTxHashesToSave == null) { btcTxHashesToSave = new HashMap<>(); } if (btcTxHashesToSave.containsKey(btcTxHash)) { return Optional.of(btcTxHashesToSave.get(btcTxHash)); } Optional<Long> height = getFromRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), BridgeSerializationUtils::deserializeOptionalLong); if (!height.isPresent()) { return height; } btcTxHashesToSave.put(btcTxHash, height.get()); return height; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void saveHeightBtcTxHashAlreadyProcessed() throws IOException { Repository repository = mock(Repository.class); Sha256Hash hash = Sha256Hash.ZERO_HASH; BridgeStorageProvider provider0 = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks ); provider0.setHeightBtcTxhashAlreadyProcessed(hash, 1L); provider0.saveHeightBtcTxHashAlreadyProcessed(); verify(repository, never()).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromString("btcTxHashesAP")); Optional<Long> result = provider0.getHeightIfBtcTxhashIsAlreadyProcessed(hash); assertTrue(result.isPresent()); assertEquals(Long.valueOf(1), result.get()); }
|
public void saveHeightBtcTxHashAlreadyProcessed() { if (btcTxHashesToSave == null) { return; } btcTxHashesToSave.forEach((btcTxHash, height) -> safeSaveToRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), height, BridgeSerializationUtils::serializeLong) ); }
|
BridgeStorageProvider { public void saveHeightBtcTxHashAlreadyProcessed() { if (btcTxHashesToSave == null) { return; } btcTxHashesToSave.forEach((btcTxHash, height) -> safeSaveToRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), height, BridgeSerializationUtils::serializeLong) ); } }
|
BridgeStorageProvider { public void saveHeightBtcTxHashAlreadyProcessed() { if (btcTxHashesToSave == null) { return; } btcTxHashesToSave.forEach((btcTxHash, height) -> safeSaveToRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), height, BridgeSerializationUtils::serializeLong) ); } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public void saveHeightBtcTxHashAlreadyProcessed() { if (btcTxHashesToSave == null) { return; } btcTxHashesToSave.forEach((btcTxHash, height) -> safeSaveToRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), height, BridgeSerializationUtils::serializeLong) ); } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public void saveHeightBtcTxHashAlreadyProcessed() { if (btcTxHashesToSave == null) { return; } btcTxHashesToSave.forEach((btcTxHash, height) -> safeSaveToRepository(getStorageKeyForBtcTxHashAlreadyProcessed(btcTxHash), height, BridgeSerializationUtils::serializeLong) ); } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getCoinBaseInformation_before_RSKIP143() { Repository repository = mock(Repository.class); Sha256Hash hash = Sha256Hash.ZERO_HASH; BridgeStorageProvider provider = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsBeforeFork ); CoinbaseInformation result = provider.getCoinbaseInformation(hash); assertNull(result); verify(repository, never()).getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("coinbaseInformation-" + hash.toString())); }
|
public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void getCoinBaseInformation_after_RSKIP143() { Repository repository = mock(Repository.class); Sha256Hash hash = Sha256Hash.ZERO_HASH; CoinbaseInformation coinbaseInformation = new CoinbaseInformation(Sha256Hash.ZERO_HASH); when(repository.getStorageBytes(PrecompiledContracts.BRIDGE_ADDR, DataWord.fromLongString("coinbaseInformation-" + hash.toString()))) .thenReturn(BridgeSerializationUtils.serializeCoinbaseInformation(coinbaseInformation)); BridgeStorageProvider provider = new BridgeStorageProvider( repository, PrecompiledContracts.BRIDGE_ADDR, config.getNetworkConstants().getBridgeConstants(), activationsAllForks ); CoinbaseInformation result = provider.getCoinbaseInformation(hash); assertEquals(coinbaseInformation.getWitnessMerkleRoot(),result.getWitnessMerkleRoot()); }
|
public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
BridgeStorageProvider { public CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash) { if (!activations.isActive(RSKIP143)) { return null; } if (coinbaseInformationMap == null) { coinbaseInformationMap = new HashMap<>(); } if (coinbaseInformationMap.containsKey(blockHash)) { return coinbaseInformationMap.get(blockHash); } CoinbaseInformation coinbaseInformation = safeGetFromRepository(getStorageKeyForCoinbaseInformation(blockHash), BridgeSerializationUtils::deserializeCoinbaseInformation); coinbaseInformationMap.put(blockHash, coinbaseInformation); return coinbaseInformation; } BridgeStorageProvider(Repository repository, RskAddress contractAddress, BridgeConstants bridgeConstants, ActivationConfig.ForBlock activations); List<UTXO> getNewFederationBtcUTXOs(); void saveNewFederationBtcUTXOs(); List<UTXO> getOldFederationBtcUTXOs(); void saveOldFederationBtcUTXOs(); Optional<Long> getHeightIfBtcTxhashIsAlreadyProcessed(Sha256Hash btcTxHash); void setHeightBtcTxhashAlreadyProcessed(Sha256Hash btcTxHash, long height); void saveHeightBtcTxHashAlreadyProcessed(); void saveBtcTxHashesAlreadyProcessed(); ReleaseRequestQueue getReleaseRequestQueue(); void saveReleaseRequestQueue(); ReleaseTransactionSet getReleaseTransactionSet(); void saveReleaseTransactionSet(); SortedMap<Keccak256, BtcTransaction> getRskTxsWaitingForSignatures(); void saveRskTxsWaitingForSignatures(); Federation getNewFederation(); void setNewFederation(Federation federation); void saveNewFederation(); Federation getOldFederation(); void setOldFederation(Federation federation); void saveOldFederation(); PendingFederation getPendingFederation(); void setPendingFederation(PendingFederation federation); void savePendingFederation(); void saveFederationElection(); ABICallElection getFederationElection(AddressBasedAuthorizer authorizer); void saveLockWhitelist(); LockWhitelist getLockWhitelist(); Coin getFeePerKb(); void setFeePerKb(Coin feePerKb); void saveFeePerKb(); void saveFeePerKbElection(); ABICallElection getFeePerKbElection(AddressBasedAuthorizer authorizer); void saveLockingCap(); void setLockingCap(Coin lockingCap); Coin getLockingCap(); CoinbaseInformation getCoinbaseInformation(Sha256Hash blockHash); void setCoinbaseInformation(Sha256Hash blockHash, CoinbaseInformation data); void save(); }
|
@Test public void membersImmutable() { boolean exception = false; try { federation.getMembers().add(new FederationMember(new BtcECKey(), new ECKey(), new ECKey())); } catch (Exception e) { exception = true; } Assert.assertTrue(exception); exception = false; try { federation.getMembers().remove(0); } catch (Exception e) { exception = true; } Assert.assertTrue(exception); }
|
public List<FederationMember> getMembers() { return members; }
|
Federation { public List<FederationMember> getMembers() { return members; } }
|
Federation { public List<FederationMember> getMembers() { return members; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { public List<FederationMember> getMembers() { return members; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { public List<FederationMember> getMembers() { return members; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void testEquals_basic() { Assert.assertTrue(federation.equals(federation)); Assert.assertFalse(federation.equals(null)); Assert.assertFalse(federation.equals(new Object())); Assert.assertFalse(federation.equals("something else")); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void testEquals_differentNumberOfMembers() { Federation otherFederation = new Federation( FederationTestUtils.getFederationMembersFromPks(100, 200, 300, 400, 500, 600, 700), ZonedDateTime.parse("2017-06-10T02:30:00Z").toInstant(), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Assert.assertFalse(federation.equals(otherFederation)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void testEquals_differentCreationTime() { Federation otherFederation = new Federation( FederationTestUtils.getFederationMembersFromPks(100, 200, 300, 400, 500, 600), ZonedDateTime.parse("2017-06-10T02:30:01Z").toInstant(), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Assert.assertFalse(federation.equals(otherFederation)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void testEncodeInt() { byte[] expected = {(byte) 0x80}; byte[] data = encodeInt(0); assertArrayEquals(expected, data); assertEquals(0, RLP.decodeInt(data, 0)); byte[] expected2 = {(byte) 0x78}; data = encodeInt(120); assertArrayEquals(expected2, data); assertEquals(120, RLP.decodeInt(data, 0)); byte[] expected3 = {(byte) 0x7F}; data = encodeInt(127); assertArrayEquals(expected3, data); assertEquals(127, RLP.decodeInt(data, 0)); assertEquals(256, RLP.decodeInt(RLP.encodeInt(256), 0)); assertEquals(255, RLP.decodeInt(RLP.encodeInt(255), 0)); assertEquals(127, RLP.decodeInt(RLP.encodeInt(127), 0)); assertEquals(128, RLP.decodeInt(RLP.encodeInt(128), 0)); data = RLP.encodeInt(1024); assertEquals(1024, RLP.decodeInt(data, 0)); byte[] expected4 = {(byte) 0x82, (byte) 0x76, (byte) 0x5F}; data = encodeInt(30303); assertArrayEquals(expected4, data); assertEquals(30303, RLP.decodeInt(data, 0)); byte[] expected5 = {(byte) 0x82, (byte) 0x4E, (byte) 0xEA}; data = encodeInt(20202); assertArrayEquals(expected5, data); assertEquals(20202, RLP.decodeInt(data, 0)); byte[] expected6 = {(byte) 0x83, 1, 0, 0}; data = encodeInt(65536); assertArrayEquals(expected6, data); assertEquals(65536, RLP.decodeInt(data, 0)); byte[] expected7 = {(byte) 0x84, (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00}; data = encodeInt(Integer.MIN_VALUE); assertArrayEquals(expected7, data); assertEquals(Integer.MIN_VALUE, RLP.decodeInt(data, 0)); byte[] expected8 = {(byte) 0x84, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}; data = encodeInt(Integer.MAX_VALUE); assertArrayEquals(expected8, data); assertEquals(Integer.MAX_VALUE, RLP.decodeInt(data, 0)); byte[] expected9 = {(byte) 0x84, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}; data = encodeInt(0xFFFFFFFF); assertArrayEquals(expected9, data); assertEquals(0xFFFFFFFF, RLP.decodeInt(data, 0)); }
|
public static byte[] encodeInt(int singleInt) { if ((singleInt & 0xFF) == singleInt) { return encodeByte((byte) singleInt); } else if ((singleInt & 0xFFFF) == singleInt) { return encodeShort((short) singleInt); } else if ((singleInt & 0xFFFFFF) == singleInt) { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 3), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 4), (byte) (singleInt >>> 24), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } }
|
RLP { public static byte[] encodeInt(int singleInt) { if ((singleInt & 0xFF) == singleInt) { return encodeByte((byte) singleInt); } else if ((singleInt & 0xFFFF) == singleInt) { return encodeShort((short) singleInt); } else if ((singleInt & 0xFFFFFF) == singleInt) { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 3), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 4), (byte) (singleInt >>> 24), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } } }
|
RLP { public static byte[] encodeInt(int singleInt) { if ((singleInt & 0xFF) == singleInt) { return encodeByte((byte) singleInt); } else if ((singleInt & 0xFFFF) == singleInt) { return encodeShort((short) singleInt); } else if ((singleInt & 0xFFFFFF) == singleInt) { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 3), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 4), (byte) (singleInt >>> 24), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } } }
|
RLP { public static byte[] encodeInt(int singleInt) { if ((singleInt & 0xFF) == singleInt) { return encodeByte((byte) singleInt); } else if ((singleInt & 0xFFFF) == singleInt) { return encodeShort((short) singleInt); } else if ((singleInt & 0xFFFFFF) == singleInt) { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 3), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 4), (byte) (singleInt >>> 24), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeInt(int singleInt) { if ((singleInt & 0xFF) == singleInt) { return encodeByte((byte) singleInt); } else if ((singleInt & 0xFFFF) == singleInt) { return encodeShort((short) singleInt); } else if ((singleInt & 0xFFFFFF) == singleInt) { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 3), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } else { return new byte[]{(byte) (OFFSET_SHORT_ITEM + 4), (byte) (singleInt >>> 24), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void testEquals_differentNetworkParameters() { Federation otherFederation = new Federation( FederationTestUtils.getFederationMembersFromPks(100, 200, 300, 400, 500, 600), ZonedDateTime.parse("2017-06-10T02:30:00Z").toInstant(), 0L, NetworkParameters.fromID(NetworkParameters.ID_TESTNET) ); Assert.assertFalse(federation.equals(otherFederation)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void testEquals_differentMembers() { List<FederationMember> members = FederationTestUtils.getFederationMembersFromPks(100, 200, 300, 400, 500); members.add(new FederationMember(BtcECKey.fromPrivate(BigInteger.valueOf(610)), ECKey.fromPrivate(BigInteger.valueOf(600)), ECKey.fromPrivate(BigInteger.valueOf(620)))); Federation otherFederation = new Federation( members, ZonedDateTime.parse("2017-06-10T02:30:00Z").toInstant(), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); members.remove(members.size()-1); members.add(new FederationMember(BtcECKey.fromPrivate(BigInteger.valueOf(600)), ECKey.fromPrivate(BigInteger.valueOf(610)), ECKey.fromPrivate(BigInteger.valueOf(620)))); Federation yetOtherFederation = new Federation( members, ZonedDateTime.parse("2017-06-10T02:30:00Z").toInstant(), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Assert.assertFalse(otherFederation.equals(yetOtherFederation)); Assert.assertFalse(federation.equals(otherFederation)); Assert.assertFalse(federation.equals(yetOtherFederation)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void testEquals_same() { Federation otherFederation = new Federation( FederationTestUtils.getFederationMembersFromPks(100, 200, 300, 400, 500, 600), ZonedDateTime.parse("2017-06-10T02:30:00Z").toInstant(), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST) ); Assert.assertTrue(federation.equals(otherFederation)); }
|
@Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { @Override public boolean equals(Object other) { if (this == other) { return true; } if (other == null || this.getClass() != other.getClass()) { return false; } Federation otherFederation = (Federation) other; return this.getNumberOfSignaturesRequired() == otherFederation.getNumberOfSignaturesRequired() && this.getSize() == otherFederation.getSize() && this.getCreationTime().equals(otherFederation.getCreationTime()) && this.creationBlockNumber == otherFederation.creationBlockNumber && this.btcParams.equals(otherFederation.btcParams) && this.members.equals(otherFederation.members); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void getBtcPublicKeyIndex() { for (int i = 0; i < federation.getBtcPublicKeys().size(); i++) { Assert.assertEquals(i, federation.getBtcPublicKeyIndex(sortedPublicKeys.get(i)).intValue()); } Assert.assertNull(federation.getBtcPublicKeyIndex(BtcECKey.fromPrivate(BigInteger.valueOf(1234)))); }
|
public Integer getBtcPublicKeyIndex(BtcECKey key) { for (int i = 0; i < members.size(); i++) { if (Arrays.equals(key.getPubKey(), members.get(i).getBtcPublicKey().getPubKey())) { return i; } } return null; }
|
Federation { public Integer getBtcPublicKeyIndex(BtcECKey key) { for (int i = 0; i < members.size(); i++) { if (Arrays.equals(key.getPubKey(), members.get(i).getBtcPublicKey().getPubKey())) { return i; } } return null; } }
|
Federation { public Integer getBtcPublicKeyIndex(BtcECKey key) { for (int i = 0; i < members.size(); i++) { if (Arrays.equals(key.getPubKey(), members.get(i).getBtcPublicKey().getPubKey())) { return i; } } return null; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { public Integer getBtcPublicKeyIndex(BtcECKey key) { for (int i = 0; i < members.size(); i++) { if (Arrays.equals(key.getPubKey(), members.get(i).getBtcPublicKey().getPubKey())) { return i; } } return null; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { public Integer getBtcPublicKeyIndex(BtcECKey key) { for (int i = 0; i < members.size(); i++) { if (Arrays.equals(key.getPubKey(), members.get(i).getBtcPublicKey().getPubKey())) { return i; } } return null; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void hasBtcPublicKey() { for (int i = 0; i < federation.getBtcPublicKeys().size(); i++) { Assert.assertTrue(federation.hasBtcPublicKey(sortedPublicKeys.get(i))); } Assert.assertFalse(federation.hasBtcPublicKey(BtcECKey.fromPrivate(BigInteger.valueOf(1234)))); }
|
public boolean hasBtcPublicKey(BtcECKey key) { return getBtcPublicKeyIndex(key) != null; }
|
Federation { public boolean hasBtcPublicKey(BtcECKey key) { return getBtcPublicKeyIndex(key) != null; } }
|
Federation { public boolean hasBtcPublicKey(BtcECKey key) { return getBtcPublicKeyIndex(key) != null; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { public boolean hasBtcPublicKey(BtcECKey key) { return getBtcPublicKeyIndex(key) != null; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { public boolean hasBtcPublicKey(BtcECKey key) { return getBtcPublicKeyIndex(key) != null; } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void hasMemberWithRskAddress() { for (int i = 0; i < federation.getBtcPublicKeys().size(); i++) { Assert.assertTrue(federation.hasMemberWithRskAddress(rskAddresses.get(i))); } byte[] nonFederateRskAddress = ECKey.fromPrivate(BigInteger.valueOf(1234)).getAddress(); Assert.assertFalse(federation.hasMemberWithRskAddress(nonFederateRskAddress)); }
|
public boolean hasMemberWithRskAddress(byte[] address) { return members.stream() .anyMatch(m -> Arrays.equals(m.getRskPublicKey().getAddress(), address)); }
|
Federation { public boolean hasMemberWithRskAddress(byte[] address) { return members.stream() .anyMatch(m -> Arrays.equals(m.getRskPublicKey().getAddress(), address)); } }
|
Federation { public boolean hasMemberWithRskAddress(byte[] address) { return members.stream() .anyMatch(m -> Arrays.equals(m.getRskPublicKey().getAddress(), address)); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { public boolean hasMemberWithRskAddress(byte[] address) { return members.stream() .anyMatch(m -> Arrays.equals(m.getRskPublicKey().getAddress(), address)); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { public boolean hasMemberWithRskAddress(byte[] address) { return members.stream() .anyMatch(m -> Arrays.equals(m.getRskPublicKey().getAddress(), address)); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void testToString() { Assert.assertEquals("4 of 6 signatures federation", federation.toString()); }
|
@Override public String toString() { return String.format("%d of %d signatures federation", getNumberOfSignaturesRequired(), members.size()); }
|
Federation { @Override public String toString() { return String.format("%d of %d signatures federation", getNumberOfSignaturesRequired(), members.size()); } }
|
Federation { @Override public String toString() { return String.format("%d of %d signatures federation", getNumberOfSignaturesRequired(), members.size()); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { @Override public String toString() { return String.format("%d of %d signatures federation", getNumberOfSignaturesRequired(), members.size()); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { @Override public String toString() { return String.format("%d of %d signatures federation", getNumberOfSignaturesRequired(), members.size()); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void isMember(){ FederationMember federationMember = federation.getMembers().get(0); Assert.assertTrue(federation.isMember(federationMember)); byte[] b = new byte[20]; new Random().nextBytes(b); ECKey invalidRskKey = ECKey.fromPrivate(b); BtcECKey invalidBtcKey = BtcECKey.fromPrivate(b); FederationMember invalidRskPubKey = new FederationMember(federationMember.getBtcPublicKey(), invalidRskKey, federationMember.getMstPublicKey()); Assert.assertFalse(federation.isMember(invalidRskPubKey)); FederationMember invalidBtcPubKey = new FederationMember(invalidBtcKey, federationMember.getRskPublicKey(), federationMember.getMstPublicKey()); Assert.assertFalse(federation.isMember(invalidBtcPubKey)); FederationMember invalidMstPubKey = new FederationMember(federationMember.getBtcPublicKey(), federationMember.getRskPublicKey(), invalidRskKey); Assert.assertFalse(federation.isMember(invalidMstPubKey)); FederationMember invalidPubKeys = new FederationMember(invalidBtcKey, invalidRskKey, invalidRskKey); Assert.assertFalse(federation.isMember(invalidPubKeys)); }
|
public boolean isMember(FederationMember federationMember){ return this.members.contains(federationMember); }
|
Federation { public boolean isMember(FederationMember federationMember){ return this.members.contains(federationMember); } }
|
Federation { public boolean isMember(FederationMember federationMember){ return this.members.contains(federationMember); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); }
|
Federation { public boolean isMember(FederationMember federationMember){ return this.members.contains(federationMember); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
Federation { public boolean isMember(FederationMember federationMember){ return this.members.contains(federationMember); } Federation(List<FederationMember> members, Instant creationTime, long creationBlockNumber, NetworkParameters btcParams); List<FederationMember> getMembers(); List<BtcECKey> getBtcPublicKeys(); int getNumberOfSignaturesRequired(); Instant getCreationTime(); NetworkParameters getBtcParams(); long getCreationBlockNumber(); Script getRedeemScript(); Script getP2SHScript(); Address getAddress(); int getSize(); Integer getBtcPublicKeyIndex(BtcECKey key); boolean hasBtcPublicKey(BtcECKey key); boolean hasMemberWithRskAddress(byte[] address); boolean isMember(FederationMember federationMember); @Override String toString(); @Override boolean equals(Object other); @Override int hashCode(); }
|
@Test public void buildAmountTo_ok() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); Coin amount = Coin.CENT.multiply(3); List<UTXO> availableUTXOs = Arrays.asList( mockUTXO("one", 0, Coin.COIN), mockUTXO("one", 1, Coin.COIN.multiply(2)), mockUTXO("two", 1, Coin.COIN.divide(2)), mockUTXO("two", 2, Coin.FIFTY_COINS), mockUTXO("two", 0, Coin.MILLICOIN.times(7)), mockUTXO("three", 0, Coin.CENT.times(3)) ); UTXOProvider utxoProvider = mock(UTXOProvider.class); when(wallet.getUTXOProvider()).thenReturn(utxoProvider); when(wallet.getWatchedAddresses()).thenReturn(Arrays.asList(changeAddress)); when(utxoProvider.getOpenTransactionOutputs(any(List.class))).then((InvocationOnMock m) -> { List<Address> addresses = m.<List>getArgument(0); Assert.assertEquals(Arrays.asList(changeAddress), addresses); return availableUTXOs; }); Mockito.doAnswer((InvocationOnMock m) -> { SendRequest sr = m.<SendRequest>getArgument(0); Assert.assertEquals(Coin.MILLICOIN.multiply(2), sr.feePerKb); Assert.assertEquals(Wallet.MissingSigsMode.USE_OP_ZERO, sr.missingSigsMode); Assert.assertEquals(changeAddress, sr.changeAddress); Assert.assertFalse(sr.shuffleOutputs); Assert.assertTrue(sr.recipientsPayFees); BtcTransaction tx = sr.tx; Assert.assertEquals(1, tx.getOutputs().size()); Assert.assertEquals(amount, tx.getOutput(0).getValue()); Assert.assertEquals(to, tx.getOutput(0).getAddressFromP2PKHScript(NetworkParameters.fromID(NetworkParameters.ID_REGTEST))); tx.addInput(mockUTXOHash("two"), 2, mock(Script.class)); tx.addInput(mockUTXOHash("three"), 0, mock(Script.class)); return null; }).when(wallet).completeTx(any(SendRequest.class)); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildAmountTo(to, amount); Assert.assertTrue(result.isPresent()); BtcTransaction tx = result.get().getBtcTx(); List<UTXO> selectedUTXOs = result.get().getSelectedUTXOs(); Assert.assertEquals(1, tx.getOutputs().size()); Assert.assertEquals(amount, tx.getOutput(0).getValue()); Assert.assertEquals(to, tx.getOutput(0).getAddressFromP2PKHScript(NetworkParameters.fromID(NetworkParameters.ID_REGTEST))); Assert.assertEquals(2, tx.getInputs().size()); Assert.assertEquals(mockUTXOHash("two"), tx.getInput(0).getOutpoint().getHash()); Assert.assertEquals(2, tx.getInput(0).getOutpoint().getIndex()); Assert.assertEquals(mockUTXOHash("three"), tx.getInput(1).getOutpoint().getHash()); Assert.assertEquals(0, tx.getInput(1).getOutpoint().getIndex()); Assert.assertEquals(2, selectedUTXOs.size()); Assert.assertEquals(mockUTXOHash("two"), selectedUTXOs.get(0).getHash()); Assert.assertEquals(2, selectedUTXOs.get(0).getIndex()); Assert.assertEquals(mockUTXOHash("three"), selectedUTXOs.get(1).getHash()); Assert.assertEquals(0, selectedUTXOs.get(1).getIndex()); }
|
public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildAmountTo_insufficientMoneyException() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); Coin amount = Coin.CENT.multiply(3); mockCompleteTxWithThrowForBuildToAmount(wallet, amount, to, new InsufficientMoneyException(Coin.valueOf(1234))); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildAmountTo(to, amount); Assert.assertFalse(result.isPresent()); verify(wallet, never()).getWatchedAddresses(); verify(wallet, never()).getUTXOProvider(); }
|
public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void test6() { byte[] expected = new byte[]{(byte) 0x80}; byte[] data = encodeBigInteger(BigInteger.ZERO); assertArrayEquals(expected, data); }
|
public static byte[] encodeBigInteger(BigInteger srcBigInteger) { if (srcBigInteger.equals(BigInteger.ZERO)) { return encodeByte((byte) 0); } else { return encodeElement(asUnsignedByteArray(srcBigInteger)); } }
|
RLP { public static byte[] encodeBigInteger(BigInteger srcBigInteger) { if (srcBigInteger.equals(BigInteger.ZERO)) { return encodeByte((byte) 0); } else { return encodeElement(asUnsignedByteArray(srcBigInteger)); } } }
|
RLP { public static byte[] encodeBigInteger(BigInteger srcBigInteger) { if (srcBigInteger.equals(BigInteger.ZERO)) { return encodeByte((byte) 0); } else { return encodeElement(asUnsignedByteArray(srcBigInteger)); } } }
|
RLP { public static byte[] encodeBigInteger(BigInteger srcBigInteger) { if (srcBigInteger.equals(BigInteger.ZERO)) { return encodeByte((byte) 0); } else { return encodeElement(asUnsignedByteArray(srcBigInteger)); } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeBigInteger(BigInteger srcBigInteger) { if (srcBigInteger.equals(BigInteger.ZERO)) { return encodeByte((byte) 0); } else { return encodeElement(asUnsignedByteArray(srcBigInteger)); } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void buildAmountTo_walletCouldNotAdjustDownwards() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); Coin amount = Coin.CENT.multiply(3); mockCompleteTxWithThrowForBuildToAmount(wallet, amount, to, new Wallet.CouldNotAdjustDownwards()); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildAmountTo(to, amount); Assert.assertFalse(result.isPresent()); verify(wallet, never()).getWatchedAddresses(); verify(wallet, never()).getUTXOProvider(); }
|
public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildAmountTo_walletExceededMaxTransactionSize() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); Coin amount = Coin.CENT.multiply(3); mockCompleteTxWithThrowForBuildToAmount(wallet, amount, to, new Wallet.ExceededMaxTransactionSize()); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildAmountTo(to, amount); Assert.assertFalse(result.isPresent()); verify(wallet, never()).getWatchedAddresses(); verify(wallet, never()).getUTXOProvider(); }
|
public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildAmountTo_utxoProviderException() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); Coin amount = Coin.CENT.multiply(3); List<UTXO> availableUTXOs = Arrays.asList( mockUTXO("one", 0, Coin.COIN), mockUTXO("one", 1, Coin.COIN.multiply(2)), mockUTXO("two", 1, Coin.COIN.divide(2)), mockUTXO("two", 2, Coin.FIFTY_COINS), mockUTXO("two", 0, Coin.MILLICOIN.times(7)), mockUTXO("three", 0, Coin.CENT.times(3)) ); UTXOProvider utxoProvider = mock(UTXOProvider.class); when(wallet.getUTXOProvider()).thenReturn(utxoProvider); when(wallet.getWatchedAddresses()).thenReturn(Arrays.asList(changeAddress)); when(utxoProvider.getOpenTransactionOutputs(any(List.class))).then((InvocationOnMock m) -> { List<Address> addresses = m.<List>getArgument(0); Assert.assertEquals(Arrays.asList(changeAddress), addresses); throw new UTXOProviderException(); }); Mockito.doAnswer((InvocationOnMock m) -> { SendRequest sr = m.<SendRequest>getArgument(0); Assert.assertEquals(Coin.MILLICOIN.multiply(2), sr.feePerKb); Assert.assertEquals(Wallet.MissingSigsMode.USE_OP_ZERO, sr.missingSigsMode); Assert.assertEquals(changeAddress, sr.changeAddress); Assert.assertFalse(sr.shuffleOutputs); Assert.assertTrue(sr.recipientsPayFees); BtcTransaction tx = sr.tx; Assert.assertEquals(1, tx.getOutputs().size()); Assert.assertEquals(amount, tx.getOutput(0).getValue()); Assert.assertEquals(to, tx.getOutput(0).getAddressFromP2PKHScript(NetworkParameters.fromID(NetworkParameters.ID_REGTEST))); tx.addInput(mockUTXOHash("two"), 2, mock(Script.class)); tx.addInput(mockUTXOHash("three"), 0, mock(Script.class)); return null; }).when(wallet).completeTx(any(SendRequest.class)); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildAmountTo(to, amount); verify(wallet, times(1)).completeTx(any(SendRequest.class)); Assert.assertFalse(result.isPresent()); }
|
public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildAmountTo(Address to, Coin amount) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(amount, to); sr.changeAddress = changeAddress; }, String.format("sending %s to %s", amount, to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildEmptyWalletTo_ok() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); List<UTXO> availableUTXOs = Arrays.asList( mockUTXO("one", 0, Coin.COIN), mockUTXO("two", 2, Coin.FIFTY_COINS), mockUTXO("two", 0, Coin.COIN.times(7)), mockUTXO("three", 0, Coin.CENT.times(3)) ); UTXOProvider utxoProvider = mock(UTXOProvider.class); when(wallet.getUTXOProvider()).thenReturn(utxoProvider); when(wallet.getWatchedAddresses()).thenReturn(Arrays.asList(to)); when(utxoProvider.getOpenTransactionOutputs(any(List.class))).then((InvocationOnMock m) -> { List<Address> addresses = m.<List>getArgument(0); Assert.assertEquals(Arrays.asList(to), addresses); return availableUTXOs; }); Mockito.doAnswer((InvocationOnMock m) -> { SendRequest sr = m.<SendRequest>getArgument(0); Assert.assertEquals(Coin.MILLICOIN.multiply(2), sr.feePerKb); Assert.assertEquals(Wallet.MissingSigsMode.USE_OP_ZERO, sr.missingSigsMode); Assert.assertEquals(to, sr.changeAddress); Assert.assertFalse(sr.shuffleOutputs); Assert.assertTrue(sr.recipientsPayFees); Assert.assertTrue(sr.emptyWallet); BtcTransaction tx = sr.tx; Assert.assertEquals(1, tx.getOutputs().size()); Assert.assertEquals(Coin.ZERO, tx.getOutput(0).getValue()); Assert.assertEquals(to, tx.getOutput(0).getAddressFromP2PKHScript(NetworkParameters.fromID(NetworkParameters.ID_REGTEST))); tx.addInput(mockUTXOHash("one"), 0, mock(Script.class)); tx.addInput(mockUTXOHash("two"), 2, mock(Script.class)); tx.addInput(mockUTXOHash("two"), 0, mock(Script.class)); tx.addInput(mockUTXOHash("three"), 0, mock(Script.class)); tx.getOutput(0).setValue(Coin.FIFTY_COINS); return null; }).when(wallet).completeTx(any(SendRequest.class)); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildEmptyWalletTo(to); Assert.assertTrue(result.isPresent()); BtcTransaction tx = result.get().getBtcTx(); List<UTXO> selectedUTXOs = result.get().getSelectedUTXOs(); Assert.assertEquals(1, tx.getOutputs().size()); Assert.assertEquals(Coin.FIFTY_COINS, tx.getOutput(0).getValue()); Assert.assertEquals(to, tx.getOutput(0).getAddressFromP2PKHScript(NetworkParameters.fromID(NetworkParameters.ID_REGTEST))); Assert.assertEquals(4, tx.getInputs().size()); Assert.assertEquals(mockUTXOHash("one"), tx.getInput(0).getOutpoint().getHash()); Assert.assertEquals(0, tx.getInput(0).getOutpoint().getIndex()); Assert.assertEquals(mockUTXOHash("two"), tx.getInput(1).getOutpoint().getHash()); Assert.assertEquals(2, tx.getInput(1).getOutpoint().getIndex()); Assert.assertEquals(mockUTXOHash("two"), tx.getInput(2).getOutpoint().getHash()); Assert.assertEquals(0, tx.getInput(2).getOutpoint().getIndex()); Assert.assertEquals(mockUTXOHash("three"), tx.getInput(3).getOutpoint().getHash()); Assert.assertEquals(0, tx.getInput(3).getOutpoint().getIndex()); Assert.assertEquals(4, selectedUTXOs.size()); Assert.assertEquals(mockUTXOHash("one"), selectedUTXOs.get(0).getHash()); Assert.assertEquals(0, selectedUTXOs.get(0).getIndex()); Assert.assertEquals(mockUTXOHash("two"), selectedUTXOs.get(1).getHash()); Assert.assertEquals(2, selectedUTXOs.get(1).getIndex()); Assert.assertEquals(mockUTXOHash("two"), selectedUTXOs.get(2).getHash()); Assert.assertEquals(0, selectedUTXOs.get(2).getIndex()); Assert.assertEquals(mockUTXOHash("three"), selectedUTXOs.get(3).getHash()); Assert.assertEquals(0, selectedUTXOs.get(3).getIndex()); }
|
public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildEmptyWalletTo_insufficientMoneyException() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); mockCompleteTxWithThrowForEmptying(wallet, to, new InsufficientMoneyException(Coin.valueOf(1234))); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildEmptyWalletTo(to); Assert.assertFalse(result.isPresent()); verify(wallet, never()).getWatchedAddresses(); verify(wallet, never()).getUTXOProvider(); }
|
public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildEmptyWalletTo_walletCouldNotAdjustDownwards() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); mockCompleteTxWithThrowForEmptying(wallet, to, new Wallet.CouldNotAdjustDownwards()); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildEmptyWalletTo(to); Assert.assertFalse(result.isPresent()); verify(wallet, never()).getWatchedAddresses(); verify(wallet, never()).getUTXOProvider(); }
|
public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildEmptyWalletTo_walletExceededMaxTransactionSize() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); mockCompleteTxWithThrowForEmptying(wallet, to, new Wallet.ExceededMaxTransactionSize()); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildEmptyWalletTo(to); Assert.assertFalse(result.isPresent()); verify(wallet, never()).getWatchedAddresses(); verify(wallet, never()).getUTXOProvider(); }
|
public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void buildEmptyWalletTo_utxoProviderException() throws InsufficientMoneyException, UTXOProviderException { Context btcContext = new Context(NetworkParameters.fromID(NetworkParameters.ID_REGTEST)); Address to = mockAddress(123); List<UTXO> availableUTXOs = Arrays.asList( mockUTXO("two", 2, Coin.FIFTY_COINS), mockUTXO("three", 0, Coin.CENT.times(3)) ); UTXOProvider utxoProvider = mock(UTXOProvider.class); when(wallet.getUTXOProvider()).thenReturn(utxoProvider); when(wallet.getWatchedAddresses()).thenReturn(Arrays.asList(to)); when(utxoProvider.getOpenTransactionOutputs(any(List.class))).then((InvocationOnMock m) -> { List<Address> addresses = m.<List>getArgument(0); Assert.assertEquals(Arrays.asList(to), addresses); throw new UTXOProviderException(); }); Mockito.doAnswer((InvocationOnMock m) -> { SendRequest sr = m.<SendRequest>getArgument(0); Assert.assertEquals(Coin.MILLICOIN.multiply(2), sr.feePerKb); Assert.assertEquals(Wallet.MissingSigsMode.USE_OP_ZERO, sr.missingSigsMode); Assert.assertEquals(to, sr.changeAddress); Assert.assertFalse(sr.shuffleOutputs); Assert.assertTrue(sr.recipientsPayFees); Assert.assertTrue(sr.emptyWallet); BtcTransaction tx = sr.tx; Assert.assertEquals(1, tx.getOutputs().size()); Assert.assertEquals(Coin.ZERO, tx.getOutput(0).getValue()); Assert.assertEquals(to, tx.getOutput(0).getAddressFromP2PKHScript(NetworkParameters.fromID(NetworkParameters.ID_REGTEST))); tx.addInput(mockUTXOHash("two"), 2, mock(Script.class)); tx.addInput(mockUTXOHash("three"), 0, mock(Script.class)); tx.getOutput(0).setValue(Coin.FIFTY_COINS); return null; }).when(wallet).completeTx(any(SendRequest.class)); Optional<ReleaseTransactionBuilder.BuildResult> result = builder.buildEmptyWalletTo(to); verify(wallet, times(1)).completeTx(any(SendRequest.class)); Assert.assertFalse(result.isPresent()); }
|
public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
ReleaseTransactionBuilder { public Optional<BuildResult> buildEmptyWalletTo(Address to) { return buildWithConfiguration((SendRequest sr) -> { sr.tx.addOutput(Coin.ZERO, to); sr.changeAddress = to; sr.emptyWallet = true; }, String.format("emptying wallet to %s", to)); } ReleaseTransactionBuilder(NetworkParameters params, Wallet wallet, Address changeAddress, Coin feePerKb); Wallet getWallet(); Address getChangeAddress(); Coin getFeePerKb(); Optional<BuildResult> buildAmountTo(Address to, Coin amount); Optional<BuildResult> buildEmptyWalletTo(Address to); }
|
@Test public void testIsLock() { NetworkParameters params = RegTestParams.get(); Context btcContext = new Context(params); BridgeRegTestConstants bridgeConstants = BridgeRegTestConstants.getInstance(); Federation federation = bridgeConstants.getGenesisFederation(); Wallet wallet = new BridgeBtcWallet(btcContext, Collections.singletonList(federation)); Address federationAddress = federation.getAddress(); wallet.addWatchedAddress(federationAddress, federation.getCreationTime().toEpochMilli()); Coin minimumLockValue = bridgeConstants.getMinimumLockTxValue(); BtcTransaction tx = new BtcTransaction(params); tx.addOutput(minimumLockValue.subtract(Coin.CENT), federationAddress); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertFalse(BridgeUtils.isLockTx(tx, federation, btcContext, bridgeConstants)); BtcTransaction tx2 = new BtcTransaction(params); tx2.addOutput(Coin.COIN, federationAddress); TransactionInput txIn = new TransactionInput(params, tx2, new byte[]{}, new TransactionOutPoint(params, 0, Sha256Hash.ZERO_HASH)); tx2.addInput(txIn); signWithNecessaryKeys(bridgeConstants.getGenesisFederation(), BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS, txIn, tx2, bridgeConstants); assertFalse(BridgeUtils.isLockTx(tx2, federation, btcContext, bridgeConstants)); BtcTransaction tx3 = new BtcTransaction(params); tx3.addOutput(Coin.COIN, federationAddress); tx3.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx3, federation, btcContext, bridgeConstants)); BtcTransaction tx4 = new BtcTransaction(params); tx4.addOutput(Coin.FIFTY_COINS, federationAddress); tx4.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx4, federation, btcContext, bridgeConstants)); }
|
public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void testIsLockForTwoFederations() { BridgeRegTestConstants bridgeConstants = BridgeRegTestConstants.getInstance(); NetworkParameters parameters = bridgeConstants.getBtcParams(); Context btcContext = new Context(parameters); List<BtcECKey> federation1Keys = Arrays.asList( BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02"))); federation1Keys.sort(BtcECKey.PUBKEY_COMPARATOR); Federation federation1 = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(federation1Keys), Instant.ofEpochMilli(1000L), 0L, parameters); List<BtcECKey> federation2Keys = Arrays.asList( BtcECKey.fromPrivate(Hex.decode("fb01")), BtcECKey.fromPrivate(Hex.decode("fb02")), BtcECKey.fromPrivate(Hex.decode("fb03"))); federation2Keys.sort(BtcECKey.PUBKEY_COMPARATOR); Federation federation2 = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(federation2Keys), Instant.ofEpochMilli(2000L), 0L, parameters); Address address1 = federation1.getAddress(); Address address2 = federation2.getAddress(); List<Federation> federations = Arrays.asList(federation1, federation2); List<Address> addresses = Arrays.asList(address1, address2); BtcTransaction tx = new BtcTransaction(parameters); tx.addOutput(Coin.CENT, address1); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertFalse(BridgeUtils.isLockTx(tx, federations, btcContext, bridgeConstants)); tx = new BtcTransaction(parameters); tx.addOutput(Coin.CENT, address2); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertFalse(BridgeUtils.isLockTx(tx, federations, btcContext, bridgeConstants)); tx = new BtcTransaction(parameters); tx.addOutput(Coin.CENT, address1); tx.addOutput(Coin.CENT, address2); tx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertFalse(BridgeUtils.isLockTx(tx, federations, btcContext, bridgeConstants)); BtcTransaction tx2 = new BtcTransaction(parameters); tx2.addOutput(Coin.COIN, address1); TransactionInput txIn = new TransactionInput(parameters, tx2, new byte[]{}, new TransactionOutPoint(parameters, 0, Sha256Hash.ZERO_HASH)); tx2.addInput(txIn); signWithNecessaryKeys(federation1, federation1Keys, txIn, tx2, bridgeConstants); assertFalse(BridgeUtils.isLockTx(tx2, federations, btcContext, bridgeConstants)); tx2 = new BtcTransaction(parameters); tx2.addOutput(Coin.COIN, address2); txIn = new TransactionInput(parameters, tx2, new byte[]{}, new TransactionOutPoint(parameters, 0, Sha256Hash.ZERO_HASH)); tx2.addInput(txIn); signWithNecessaryKeys(federation2, federation2Keys, txIn, tx2, bridgeConstants); assertFalse(BridgeUtils.isLockTx(tx2, federations, btcContext, bridgeConstants)); tx2 = new BtcTransaction(parameters); tx2.addOutput(Coin.COIN, address1); tx2.addOutput(Coin.COIN, address2); txIn = new TransactionInput(parameters, tx2, new byte[]{}, new TransactionOutPoint(parameters, 0, Sha256Hash.ZERO_HASH)); tx2.addInput(txIn); signWithNecessaryKeys(federation1, federation1Keys, txIn, tx2, bridgeConstants); assertFalse(BridgeUtils.isLockTx(tx2, federations, btcContext, bridgeConstants)); tx2 = new BtcTransaction(parameters); tx2.addOutput(Coin.COIN, address1); tx2.addOutput(Coin.COIN, address2); txIn = new TransactionInput(parameters, tx2, new byte[]{}, new TransactionOutPoint(parameters, 0, Sha256Hash.ZERO_HASH)); tx2.addInput(txIn); signWithNecessaryKeys(federation2, federation2Keys, txIn, tx2, bridgeConstants); assertFalse(BridgeUtils.isLockTx(tx2, federations, btcContext, bridgeConstants)); BtcTransaction tx3 = new BtcTransaction(parameters); tx3.addOutput(Coin.COIN, address1); tx3.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx3, federations, btcContext, bridgeConstants)); tx3 = new BtcTransaction(parameters); tx3.addOutput(Coin.COIN, address2); tx3.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx3, federations, btcContext, bridgeConstants)); tx3 = new BtcTransaction(parameters); tx3.addOutput(Coin.COIN, address1); tx3.addOutput(Coin.COIN, address2); tx3.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx3, federations, btcContext, bridgeConstants)); BtcTransaction tx4 = new BtcTransaction(parameters); tx4.addOutput(Coin.FIFTY_COINS, address1); tx4.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx4, federations, btcContext, bridgeConstants)); tx4 = new BtcTransaction(parameters); tx4.addOutput(Coin.FIFTY_COINS, address2); tx4.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx4, federations, btcContext, bridgeConstants)); tx4 = new BtcTransaction(parameters); tx4.addOutput(Coin.FIFTY_COINS, address1); tx4.addOutput(Coin.FIFTY_COINS, address2); tx4.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertTrue(BridgeUtils.isLockTx(tx4, federations, btcContext, bridgeConstants)); }
|
public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants) { for (int i = 0; i < tx.getInputs().size(); i++) { final int index = i; if (federations.stream().anyMatch(federation -> scriptCorrectlySpendsTx(tx, index, federation.getP2SHScript()))) { return false; } } Wallet federationsWallet = BridgeUtils.getFederationsNoSpendWallet(btcContext, federations); Coin valueSentToMe = tx.getValueSentToMe(federationsWallet); int valueSentToMeSignum = valueSentToMe.signum(); if (valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())) { logger.warn("[btctx:{}]Someone sent to the federation less than {} satoshis", tx.getHash(), bridgeConstants.getMinimumLockTxValue()); } return (valueSentToMeSignum > 0 && !valueSentToMe.isLessThan(bridgeConstants.getMinimumLockTxValue())); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void test7() { byte[] data = encodeString(""); assertArrayEquals(new byte[]{(byte) 0x80}, data); byte[] expected = {(byte) 0x90, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x4A, (byte) 0x20, (byte) 0x43, (byte) 0x6C, (byte) 0x69, (byte) 0x65, (byte) 0x6E, (byte) 0x74}; String test = "EthereumJ Client"; data = encodeString(test); assertArrayEquals(expected, data); String test2 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++"; byte[] expected2 = {(byte) 0xAD, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x28, (byte) 0x2B, (byte) 0x2B, (byte) 0x29, (byte) 0x2F, (byte) 0x5A, (byte) 0x65, (byte) 0x72, (byte) 0x6F, (byte) 0x47, (byte) 0x6F, (byte) 0x78, (byte) 0x2F, (byte) 0x76, (byte) 0x30, (byte) 0x2E, (byte) 0x35, (byte) 0x2E, (byte) 0x30, (byte) 0x2F, (byte) 0x6E, (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x2F, (byte) 0x4C, (byte) 0x69, (byte) 0x6E, (byte) 0x75, (byte) 0x78, (byte) 0x2F, (byte) 0x67, (byte) 0x2B, (byte) 0x2B}; data = encodeString(test2); assertArrayEquals(expected2, data); String test3 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++"; byte[] expected3 = {(byte) 0xB8, (byte) 0x5A, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x28, (byte) 0x2B, (byte) 0x2B, (byte) 0x29, (byte) 0x2F, (byte) 0x5A, (byte) 0x65, (byte) 0x72, (byte) 0x6F, (byte) 0x47, (byte) 0x6F, (byte) 0x78, (byte) 0x2F, (byte) 0x76, (byte) 0x30, (byte) 0x2E, (byte) 0x35, (byte) 0x2E, (byte) 0x30, (byte) 0x2F, (byte) 0x6E, (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x2F, (byte) 0x4C, (byte) 0x69, (byte) 0x6E, (byte) 0x75, (byte) 0x78, (byte) 0x2F, (byte) 0x67, (byte) 0x2B, (byte) 0x2B, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x28, (byte) 0x2B, (byte) 0x2B, (byte) 0x29, (byte) 0x2F, (byte) 0x5A, (byte) 0x65, (byte) 0x72, (byte) 0x6F, (byte) 0x47, (byte) 0x6F, (byte) 0x78, (byte) 0x2F, (byte) 0x76, (byte) 0x30, (byte) 0x2E, (byte) 0x35, (byte) 0x2E, (byte) 0x30, (byte) 0x2F, (byte) 0x6E, (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x2F, (byte) 0x4C, (byte) 0x69, (byte) 0x6E, (byte) 0x75, (byte) 0x78, (byte) 0x2F, (byte) 0x67, (byte) 0x2B, (byte) 0x2B}; data = encodeString(test3); assertArrayEquals(expected3, data); }
|
public static byte[] encodeString(String srcString) { return encodeElement(srcString.getBytes(StandardCharsets.UTF_8)); }
|
RLP { public static byte[] encodeString(String srcString) { return encodeElement(srcString.getBytes(StandardCharsets.UTF_8)); } }
|
RLP { public static byte[] encodeString(String srcString) { return encodeElement(srcString.getBytes(StandardCharsets.UTF_8)); } }
|
RLP { public static byte[] encodeString(String srcString) { return encodeElement(srcString.getBytes(StandardCharsets.UTF_8)); } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeString(String srcString) { return encodeElement(srcString.getBytes(StandardCharsets.UTF_8)); } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void testTxIsProcessable() { ActivationConfig.ForBlock actForBlock = mock(ActivationConfig.ForBlock.class); when(actForBlock.isActive(ConsensusRule.RSKIP143)).thenReturn(false); assertTrue(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2PKH, actForBlock)); assertFalse(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2SHP2WPKH, actForBlock)); assertFalse(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2SHMULTISIG, actForBlock)); assertFalse(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2SHP2WSH, actForBlock)); when(actForBlock.isActive(ConsensusRule.RSKIP143)).thenReturn(true); assertTrue(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2PKH, actForBlock)); assertTrue(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2SHP2WPKH, actForBlock)); assertTrue(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2SHMULTISIG, actForBlock)); assertTrue(BridgeUtils.txIsProcessable(BtcLockSender.TxType.P2SHP2WSH, actForBlock)); }
|
public static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations) { return txType == BtcLockSender.TxType.P2PKH || activations.isActive(ConsensusRule.RSKIP143); }
|
BridgeUtils { public static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations) { return txType == BtcLockSender.TxType.P2PKH || activations.isActive(ConsensusRule.RSKIP143); } }
|
BridgeUtils { public static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations) { return txType == BtcLockSender.TxType.P2PKH || activations.isActive(ConsensusRule.RSKIP143); } }
|
BridgeUtils { public static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations) { return txType == BtcLockSender.TxType.P2PKH || activations.isActive(ConsensusRule.RSKIP143); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations) { return txType == BtcLockSender.TxType.P2PKH || activations.isActive(ConsensusRule.RSKIP143); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void testIsMigrationTx() { BridgeRegTestConstants bridgeConstants = BridgeRegTestConstants.getInstance(); NetworkParameters parameters = bridgeConstants.getBtcParams(); Context btcContext = new Context(parameters); List<BtcECKey> activeFederationKeys = Stream.of( BtcECKey.fromPrivate(Hex.decode("fa01")), BtcECKey.fromPrivate(Hex.decode("fa02")) ).sorted(BtcECKey.PUBKEY_COMPARATOR).collect(Collectors.toList()); Federation activeFederation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(activeFederationKeys), Instant.ofEpochMilli(2000L), 2L, parameters); List<BtcECKey> retiringFederationKeys = Stream.of( BtcECKey.fromPrivate(Hex.decode("fb01")), BtcECKey.fromPrivate(Hex.decode("fb02")), BtcECKey.fromPrivate(Hex.decode("fb03")) ).sorted(BtcECKey.PUBKEY_COMPARATOR).collect(Collectors.toList()); Federation retiringFederation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(retiringFederationKeys), Instant.ofEpochMilli(1000L), 1L, parameters); Address activeFederationAddress = activeFederation.getAddress(); BtcTransaction migrationTx = new BtcTransaction(parameters); migrationTx.addOutput(Coin.COIN, activeFederationAddress); TransactionInput migrationTxInput = new TransactionInput(parameters, migrationTx, new byte[]{}, new TransactionOutPoint(parameters, 0, Sha256Hash.ZERO_HASH)); migrationTx.addInput(migrationTxInput); signWithNecessaryKeys(retiringFederation, retiringFederationKeys, migrationTxInput, migrationTx, bridgeConstants); assertThat(BridgeUtils.isMigrationTx(migrationTx, activeFederation, retiringFederation, btcContext, bridgeConstants), is(true)); BtcTransaction toActiveFederationTx = new BtcTransaction(parameters); toActiveFederationTx.addOutput(Coin.COIN, activeFederationAddress); toActiveFederationTx.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[]{})); assertThat(BridgeUtils.isMigrationTx(toActiveFederationTx, activeFederation, retiringFederation, btcContext, bridgeConstants), is(false)); Address randomAddress = Address.fromBase58( NetworkParameters.fromID(NetworkParameters.ID_REGTEST), "n3PLxDiwWqa5uH7fSbHCxS6VAjD9Y7Rwkj" ); BtcTransaction fromRetiringFederationTx = new BtcTransaction(parameters); fromRetiringFederationTx.addOutput(Coin.COIN, randomAddress); TransactionInput fromRetiringFederationTxInput = new TransactionInput(parameters, fromRetiringFederationTx, new byte[]{}, new TransactionOutPoint(parameters, 0, Sha256Hash.ZERO_HASH)); fromRetiringFederationTx.addInput(fromRetiringFederationTxInput); signWithNecessaryKeys(retiringFederation, retiringFederationKeys, fromRetiringFederationTxInput, fromRetiringFederationTx, bridgeConstants); assertThat(BridgeUtils.isMigrationTx(fromRetiringFederationTx, activeFederation, retiringFederation, btcContext, bridgeConstants), is(false)); assertThat(BridgeUtils.isMigrationTx(migrationTx, activeFederation, null, btcContext, bridgeConstants), is(false)); }
|
public static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants) { if (retiringFederation == null) { return false; } boolean moveFromRetiring = isReleaseTx(btcTx, retiringFederation); boolean moveToActive = isLockTx(btcTx, activeFederation, btcContext, bridgeConstants); return moveFromRetiring && moveToActive; }
|
BridgeUtils { public static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants) { if (retiringFederation == null) { return false; } boolean moveFromRetiring = isReleaseTx(btcTx, retiringFederation); boolean moveToActive = isLockTx(btcTx, activeFederation, btcContext, bridgeConstants); return moveFromRetiring && moveToActive; } }
|
BridgeUtils { public static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants) { if (retiringFederation == null) { return false; } boolean moveFromRetiring = isReleaseTx(btcTx, retiringFederation); boolean moveToActive = isLockTx(btcTx, activeFederation, btcContext, bridgeConstants); return moveFromRetiring && moveToActive; } }
|
BridgeUtils { public static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants) { if (retiringFederation == null) { return false; } boolean moveFromRetiring = isReleaseTx(btcTx, retiringFederation); boolean moveToActive = isLockTx(btcTx, activeFederation, btcContext, bridgeConstants); return moveFromRetiring && moveToActive; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants) { if (retiringFederation == null) { return false; } boolean moveFromRetiring = isReleaseTx(btcTx, retiringFederation); boolean moveToActive = isLockTx(btcTx, activeFederation, btcContext, bridgeConstants); return moveFromRetiring && moveToActive; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void getAddressFromEthTransaction() { org.ethereum.core.Transaction tx = new org.ethereum.core.Transaction(TO_ADDRESS, AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA, constants.getChainId()); byte[] privKey = generatePrivKey(); tx.sign(privKey); Address expectedAddress = BtcECKey.fromPrivate(privKey).toAddress(RegTestParams.get()); Address result = BridgeUtils.recoverBtcAddressFromEthTransaction(tx, RegTestParams.get()); assertEquals(expectedAddress, result); }
|
public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test(expected = Exception.class) public void getAddressFromEthNotSignTransaction() { org.ethereum.core.Transaction tx = new org.ethereum.core.Transaction(TO_ADDRESS, AMOUNT, NONCE, GAS_PRICE, GAS_LIMIT, DATA, constants.getChainId()); BridgeUtils.recoverBtcAddressFromEthTransaction(tx, RegTestParams.get()); }
|
public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters) { org.ethereum.crypto.ECKey key = tx.getKey(); byte[] pubKey = key.getPubKey(true); return BtcECKey.fromPublicOnly(pubKey).toAddress(networkParameters); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void hasEnoughSignatures_two_signatures() { byte[] sign1 = new byte[]{0x79}; byte[] sign2 = new byte[]{0x78}; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, sign2), 1); Assert.assertTrue(BridgeUtils.hasEnoughSignatures(mock(Context.class), btcTx)); }
|
public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void hasEnoughSignatures_one_signature() { byte[] sign1 = new byte[]{0x79}; byte[] MISSING_SIGNATURE = new byte[0]; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, MISSING_SIGNATURE), 1); Assert.assertFalse(BridgeUtils.hasEnoughSignatures(mock(Context.class), btcTx)); }
|
public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void hasEnoughSignatures_no_signatures() { BtcTransaction btcTx = createReleaseTx(Collections.emptyList(), 1); Assert.assertFalse(BridgeUtils.hasEnoughSignatures(mock(Context.class), btcTx)); }
|
public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void hasEnoughSignatures_several_inputs_all_signed() { byte[] sign1 = new byte[]{0x79}; byte[] sign2 = new byte[]{0x78}; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, sign2), 3); Assert.assertTrue(BridgeUtils.hasEnoughSignatures(mock(Context.class), btcTx)); }
|
public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void hasEnoughSignatures_several_inputs_one_missing_signature() { byte[] sign1 = new byte[]{0x79}; byte[] MISSING_SIGNATURE = new byte[0]; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, MISSING_SIGNATURE), 3); Assert.assertFalse(BridgeUtils.hasEnoughSignatures(mock(Context.class), btcTx)); }
|
public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); for (TransactionInput input : btcTx.getInputs()) { Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size(); i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { return false; } } } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void countMissingSignatures_two_signatures() { byte[] sign1 = new byte[]{0x79}; byte[] sign2 = new byte[]{0x78}; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, sign2), 1); Assert.assertEquals(0, BridgeUtils.countMissingSignatures(mock(Context.class), btcTx)); }
|
public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void test8() { String byteArr = "ce73660a06626c1b3fda7b18ef7ba3ce17b6bf604f9541d3c6c654b7ae88b239" + "407f659c78f419025d785727ed017b6add21952d7e12007373e321dbc31824ba"; byte[] byteArray = Hex.decode(byteArr); String expected = "b840" + byteArr; assertEquals(expected, ByteUtil.toHexString(encodeElement(byteArray))); }
|
public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeElement(@Nullable byte[] srcData) { if (srcData == null || srcData.length == 0) { return new byte[]{(byte) OFFSET_SHORT_ITEM}; } else if (isSingleZero(srcData)) { return srcData; } else if (srcData.length == 1 && (srcData[0] & 0xFF) < OFFSET_SHORT_ITEM) { return srcData; } else if (srcData.length < SIZE_THRESHOLD) { byte length = (byte) (OFFSET_SHORT_ITEM + srcData.length); byte[] data = Arrays.copyOf(srcData, srcData.length + 1); System.arraycopy(data, 0, data, 1, srcData.length); data[0] = length; return data; } else { int tmpLength = srcData.length; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((srcData.length >> (8 * i)) & 0xFF); } byte[] data = Arrays.copyOf(srcData, srcData.length + 1 + byteNum); System.arraycopy(data, 0, data, 1 + byteNum, srcData.length); data[0] = (byte) (OFFSET_LONG_ITEM + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); return data; } } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void countMissingSignatures_one_signature() { byte[] sign1 = new byte[]{0x79}; byte[] MISSING_SIGNATURE = new byte[0]; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, MISSING_SIGNATURE), 1); Assert.assertEquals(1, BridgeUtils.countMissingSignatures(mock(Context.class), btcTx)); }
|
public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void countMissingSignatures_no_signatures() { BtcTransaction btcTx = createReleaseTx(Collections.emptyList(), 1); Assert.assertEquals(2, BridgeUtils.countMissingSignatures(mock(Context.class), btcTx)); }
|
public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void countMissingSignatures_several_inputs_all_signed() { byte[] sign1 = new byte[]{0x79}; byte[] sign2 = new byte[]{0x78}; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, sign2), 3); Assert.assertEquals(0, BridgeUtils.countMissingSignatures(mock(Context.class), btcTx)); }
|
public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void countMissingSignatures_several_inputs_one_missing_signature() { byte[] sign1 = new byte[]{0x79}; byte[] MISSING_SIGNATURE = new byte[0]; BtcTransaction btcTx = createReleaseTx(Arrays.asList(sign1, MISSING_SIGNATURE), 3); Assert.assertEquals(1, BridgeUtils.countMissingSignatures(mock(Context.class), btcTx)); }
|
public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static int countMissingSignatures(Context btcContext, BtcTransaction btcTx) { Context.propagate(btcContext); int unsigned = 0; TransactionInput input = btcTx.getInput(0); Script scriptSig = input.getScriptSig(); List<ScriptChunk> chunks = scriptSig.getChunks(); for (int i = 1; i < chunks.size() - 1; i++) { ScriptChunk chunk = chunks.get(i); if (!chunk.isOpCode() && chunk.data.length == 0) { unsigned++; } } return unsigned; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void isFreeBridgeTxTrue() { activationConfig = ActivationConfigsForTest.bridgeUnitTest(); isFreeBridgeTx(true, PrecompiledContracts.BRIDGE_ADDR, BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS.get(0).getPrivKeyBytes()); }
|
public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void isFreeBridgeTxOtherContract() { activationConfig = ActivationConfigsForTest.bridgeUnitTest(); isFreeBridgeTx(false, PrecompiledContracts.IDENTITY_ADDR, BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS.get(0).getPrivKeyBytes()); }
|
public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void isFreeBridgeTxFreeTxDisabled() { activationConfig = ActivationConfigsForTest.only(ConsensusRule.ARE_BRIDGE_TXS_PAID); isFreeBridgeTx(false, PrecompiledContracts.BRIDGE_ADDR, BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS.get(0).getPrivKeyBytes()); }
|
public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void isFreeBridgeTxNonFederatorKey() { activationConfig = ActivationConfigsForTest.bridgeUnitTest(); isFreeBridgeTx(false, PrecompiledContracts.BRIDGE_ADDR, new BtcECKey().getPrivKeyBytes()); }
|
public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations) { RskAddress receiveAddress = rskTx.getReceiveAddress(); if (receiveAddress.equals(RskAddress.nullAddress())) { return false; } BridgeConstants bridgeConstants = constants.getBridgeConstants(); return PrecompiledContracts.BRIDGE_ADDR.equals(receiveAddress) && !activations.isActive(ConsensusRule.ARE_BRIDGE_TXS_PAID) && rskTx.acceptTransactionSignature(constants.getChainId()) && ( isFromFederateMember(rskTx, bridgeConstants.getGenesisFederation()) || isFromFederationChangeAuthorizedSender(rskTx, bridgeConstants) || isFromLockWhitelistChangeAuthorizedSender(rskTx, bridgeConstants) || isFromFeePerKbChangeAuthorizedSender(rskTx, bridgeConstants) ); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void getFederationNoSpendWallet() { NetworkParameters regTestParameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST); Federation federation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(Arrays.asList( BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")), BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5")))), Instant.ofEpochMilli(5005L), 0L, regTestParameters); Context mockedBtcContext = mock(Context.class); when(mockedBtcContext.getParams()).thenReturn(regTestParameters); Wallet wallet = BridgeUtils.getFederationNoSpendWallet(mockedBtcContext, federation); Assert.assertEquals(BridgeBtcWallet.class, wallet.getClass()); assertIsWatching(federation.getAddress(), wallet, regTestParameters); }
|
public static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation) { return getFederationsNoSpendWallet(btcContext, Collections.singletonList(federation)); }
|
BridgeUtils { public static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation) { return getFederationsNoSpendWallet(btcContext, Collections.singletonList(federation)); } }
|
BridgeUtils { public static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation) { return getFederationsNoSpendWallet(btcContext, Collections.singletonList(federation)); } }
|
BridgeUtils { public static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation) { return getFederationsNoSpendWallet(btcContext, Collections.singletonList(federation)); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation) { return getFederationsNoSpendWallet(btcContext, Collections.singletonList(federation)); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void getFederationSpendWallet() throws UTXOProviderException { NetworkParameters regTestParameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST); Federation federation = new Federation(FederationTestUtils.getFederationMembersWithBtcKeys(Arrays.asList( BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")), BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5")))), Instant.ofEpochMilli(5005L), 0L, regTestParameters); Context mockedBtcContext = mock(Context.class); when(mockedBtcContext.getParams()).thenReturn(regTestParameters); List<UTXO> mockedUtxos = new ArrayList<>(); mockedUtxos.add(mock(UTXO.class)); mockedUtxos.add(mock(UTXO.class)); mockedUtxos.add(mock(UTXO.class)); Wallet wallet = BridgeUtils.getFederationSpendWallet(mockedBtcContext, federation, mockedUtxos); Assert.assertEquals(BridgeBtcWallet.class, wallet.getClass()); assertIsWatching(federation.getAddress(), wallet, regTestParameters); CoinSelector selector = wallet.getCoinSelector(); Assert.assertEquals(RskAllowUnconfirmedCoinSelector.class, selector.getClass()); UTXOProvider utxoProvider = wallet.getUTXOProvider(); Assert.assertEquals(RskUTXOProvider.class, utxoProvider.getClass()); Assert.assertEquals(mockedUtxos, utxoProvider.getOpenTransactionOutputs(Collections.emptyList())); }
|
public static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos) { return getFederationsSpendWallet(btcContext, Collections.singletonList(federation), utxos); }
|
BridgeUtils { public static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos) { return getFederationsSpendWallet(btcContext, Collections.singletonList(federation), utxos); } }
|
BridgeUtils { public static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos) { return getFederationsSpendWallet(btcContext, Collections.singletonList(federation), utxos); } }
|
BridgeUtils { public static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos) { return getFederationsSpendWallet(btcContext, Collections.singletonList(federation), utxos); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos) { return getFederationsSpendWallet(btcContext, Collections.singletonList(federation), utxos); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void test9() { byte[] actuals = encodeList(); assertArrayEquals(new byte[]{(byte) 0xc0}, actuals); }
|
public static byte[] encodeList(byte[]... elements) { if (elements == null) { return new byte[]{(byte) OFFSET_SHORT_LIST}; } int totalLength = 0; for (byte[] element1 : elements) { totalLength += element1.length; } byte[] data; int copyPos; if (totalLength < SIZE_THRESHOLD) { data = new byte[1 + totalLength]; data[0] = (byte) (OFFSET_SHORT_LIST + totalLength); copyPos = 1; } else { int tmpLength = totalLength; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } tmpLength = totalLength; byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((tmpLength >> (8 * i)) & 0xFF); } data = new byte[1 + lenBytes.length + totalLength]; data[0] = (byte) (OFFSET_LONG_LIST + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); copyPos = lenBytes.length + 1; } for (byte[] element : elements) { System.arraycopy(element, 0, data, copyPos, element.length); copyPos += element.length; } return data; }
|
RLP { public static byte[] encodeList(byte[]... elements) { if (elements == null) { return new byte[]{(byte) OFFSET_SHORT_LIST}; } int totalLength = 0; for (byte[] element1 : elements) { totalLength += element1.length; } byte[] data; int copyPos; if (totalLength < SIZE_THRESHOLD) { data = new byte[1 + totalLength]; data[0] = (byte) (OFFSET_SHORT_LIST + totalLength); copyPos = 1; } else { int tmpLength = totalLength; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } tmpLength = totalLength; byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((tmpLength >> (8 * i)) & 0xFF); } data = new byte[1 + lenBytes.length + totalLength]; data[0] = (byte) (OFFSET_LONG_LIST + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); copyPos = lenBytes.length + 1; } for (byte[] element : elements) { System.arraycopy(element, 0, data, copyPos, element.length); copyPos += element.length; } return data; } }
|
RLP { public static byte[] encodeList(byte[]... elements) { if (elements == null) { return new byte[]{(byte) OFFSET_SHORT_LIST}; } int totalLength = 0; for (byte[] element1 : elements) { totalLength += element1.length; } byte[] data; int copyPos; if (totalLength < SIZE_THRESHOLD) { data = new byte[1 + totalLength]; data[0] = (byte) (OFFSET_SHORT_LIST + totalLength); copyPos = 1; } else { int tmpLength = totalLength; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } tmpLength = totalLength; byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((tmpLength >> (8 * i)) & 0xFF); } data = new byte[1 + lenBytes.length + totalLength]; data[0] = (byte) (OFFSET_LONG_LIST + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); copyPos = lenBytes.length + 1; } for (byte[] element : elements) { System.arraycopy(element, 0, data, copyPos, element.length); copyPos += element.length; } return data; } }
|
RLP { public static byte[] encodeList(byte[]... elements) { if (elements == null) { return new byte[]{(byte) OFFSET_SHORT_LIST}; } int totalLength = 0; for (byte[] element1 : elements) { totalLength += element1.length; } byte[] data; int copyPos; if (totalLength < SIZE_THRESHOLD) { data = new byte[1 + totalLength]; data[0] = (byte) (OFFSET_SHORT_LIST + totalLength); copyPos = 1; } else { int tmpLength = totalLength; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } tmpLength = totalLength; byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((tmpLength >> (8 * i)) & 0xFF); } data = new byte[1 + lenBytes.length + totalLength]; data[0] = (byte) (OFFSET_LONG_LIST + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); copyPos = lenBytes.length + 1; } for (byte[] element : elements) { System.arraycopy(element, 0, data, copyPos, element.length); copyPos += element.length; } return data; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
RLP { public static byte[] encodeList(byte[]... elements) { if (elements == null) { return new byte[]{(byte) OFFSET_SHORT_LIST}; } int totalLength = 0; for (byte[] element1 : elements) { totalLength += element1.length; } byte[] data; int copyPos; if (totalLength < SIZE_THRESHOLD) { data = new byte[1 + totalLength]; data[0] = (byte) (OFFSET_SHORT_LIST + totalLength); copyPos = 1; } else { int tmpLength = totalLength; byte byteNum = 0; while (tmpLength != 0) { ++byteNum; tmpLength = tmpLength >> 8; } tmpLength = totalLength; byte[] lenBytes = new byte[byteNum]; for (int i = 0; i < byteNum; ++i) { lenBytes[byteNum - 1 - i] = (byte) ((tmpLength >> (8 * i)) & 0xFF); } data = new byte[1 + lenBytes.length + totalLength]; data[0] = (byte) (OFFSET_LONG_LIST + byteNum); System.arraycopy(lenBytes, 0, data, 1, lenBytes.length); copyPos = lenBytes.length + 1; } for (byte[] element : elements) { System.arraycopy(element, 0, data, copyPos, element.length); copyPos += element.length; } return data; } static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
int endPos, int levelToIndex, Queue<Integer> index); @Nonnull static ArrayList<RLPElement> decode2(@CheckForNull byte[] msgData); static RLPElement decodeFirstElement(@CheckForNull byte[] msgData, int position); static RLPList decodeList(byte[] msgData); @Nullable static RLPElement decode2OneItem(@CheckForNull byte[] msgData, int startPos); @Nonnull static RskAddress parseRskAddress(@Nullable byte[] bytes); @Nonnull static Coin parseCoin(@Nullable byte[] bytes); @Nullable static Coin parseCoinNonNullZero(byte[] bytes); @Nullable static Coin parseSignedCoinNonNullZero(byte[] bytes); static Coin parseCoinNullZero(@Nullable byte[] bytes); @Nullable static BlockDifficulty parseBlockDifficulty(@Nullable byte[] bytes); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeRskAddress(RskAddress addr); static byte[] encodeCoin(@Nullable Coin coin); static byte[] encodeCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeSignedCoinNonNullZero(@CheckForNull Coin coin); static byte[] encodeCoinNullZero(Coin coin); static byte[] encodeBlockDifficulty(BlockDifficulty difficulty); static byte[] encodeElement(@Nullable byte[] srcData); static byte[] encodeListHeader(int size); static byte[] encodeSet(Set<ByteArrayWrapper> data); static byte[] encodeList(byte[]... elements); static byte[] encodedEmptyList(); static byte[] encodedEmptyByteArray(); }
|
@Test public void net_version() throws Exception { Web3Impl web3 = createWeb3(); String netVersion = web3.net_version(); assertTrue("RSK net version different than expected", netVersion.compareTo(Byte.toString(config.getNetworkConstants().getChainId())) == 0); }
|
@Override public String net_version() { String s = null; try { byte netVersion = config.getNetworkConstants().getChainId(); return s = Byte.toString(netVersion); } finally { if (logger.isDebugEnabled()) { logger.debug("net_version(): {}", s); } } }
|
Web3Impl implements Web3 { @Override public String net_version() { String s = null; try { byte netVersion = config.getNetworkConstants().getChainId(); return s = Byte.toString(netVersion); } finally { if (logger.isDebugEnabled()) { logger.debug("net_version(): {}", s); } } } }
|
Web3Impl implements Web3 { @Override public String net_version() { String s = null; try { byte netVersion = config.getNetworkConstants().getChainId(); return s = Byte.toString(netVersion); } finally { if (logger.isDebugEnabled()) { logger.debug("net_version(): {}", s); } } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); }
|
Web3Impl implements Web3 { @Override public String net_version() { String s = null; try { byte netVersion = config.getNetworkConstants().getChainId(); return s = Byte.toString(netVersion); } finally { if (logger.isDebugEnabled()) { logger.debug("net_version(): {}", s); } } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); }
|
Web3Impl implements Web3 { @Override public String net_version() { String s = null; try { byte netVersion = config.getNetworkConstants().getChainId(); return s = Byte.toString(netVersion); } finally { if (logger.isDebugEnabled()) { logger.debug("net_version(): {}", s); } } } protected Web3Impl(
Ethereum eth,
Blockchain blockchain,
BlockStore blockStore,
ReceiptStore receiptStore,
RskSystemProperties config,
MinerClient minerClient,
MinerServer minerServer,
PersonalModule personalModule,
EthModule ethModule,
EvmModule evmModule,
TxPoolModule txPoolModule,
MnrModule mnrModule,
DebugModule debugModule,
TraceModule traceModule,
RskModule rskModule,
ChannelManager channelManager,
PeerScoringManager peerScoringManager,
PeerServer peerServer,
BlockProcessor nodeBlockProcessor,
HashRateCalculator hashRateCalculator,
ConfigCapabilities configCapabilities,
BuildInfo buildInfo,
BlocksBloomStore blocksBloomStore,
Web3InformationRetriever web3InformationRetriever); @Override void start(); @Override void stop(); @Override String web3_clientVersion(); @Override String web3_sha3(String data); @Override String net_version(); @Override String net_peerCount(); @Override boolean net_listening(); @Override String rsk_protocolVersion(); @Override String eth_protocolVersion(); @Override Object eth_syncing(); @Override String eth_coinbase(); @Override boolean eth_mining(); @Override BigInteger eth_hashrate(); @Override BigInteger eth_netHashrate(); @Override String[] net_peerList(); @Override String eth_gasPrice(); @Override String eth_blockNumber(); @Override String eth_getBalance(String address, String block); @Override String eth_getBalance(String address); @Override String eth_getStorageAt(String address, String storageIdx, String blockId); @Override String eth_getTransactionCount(String address, String blockId); Block getBlockByJSonHash(String blockHash); @Override String eth_getBlockTransactionCountByHash(String blockHash); static Block getBlockByNumberOrStr(String bnOrId, Blockchain blockchain); @Override String eth_getBlockTransactionCountByNumber(String bnOrId); @Override String eth_getUncleCountByBlockHash(String blockHash); @Override String eth_getUncleCountByBlockNumber(String bnOrId); BlockInformationResult getBlockInformationResult(BlockInformation blockInformation); BlockResultDTO getBlockResult(Block b, boolean fullTx); BlockInformationResult[] eth_getBlocksByNumber(String number); @Override BlockResultDTO eth_getBlockByHash(String blockHash, Boolean fullTransactionObjects); @Override BlockResultDTO eth_getBlockByNumber(String bnOrId, Boolean fullTransactionObjects); @Override TransactionResultDTO eth_getTransactionByHash(String transactionHash); @Override TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index); @Override TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index); @Override TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash); @Override BlockResultDTO eth_getUncleByBlockHashAndIndex(String blockHash, String uncleIdx); @Override BlockResultDTO eth_getUncleByBlockNumberAndIndex(String blockId, String uncleIdx); @Override String[] eth_getCompilers(); @Override Map<String, CompilationResultDTO> eth_compileLLL(String contract); @Override Map<String, CompilationResultDTO> eth_compileSerpent(String contract); @Override Map<String, CompilationResultDTO> eth_compileSolidity(String contract); @Override String eth_newFilter(FilterRequest fr); @Override String eth_newBlockFilter(); @Override String eth_newPendingTransactionFilter(); @Override boolean eth_uninstallFilter(String id); @Override Object[] eth_getFilterChanges(String id); @Override Object[] eth_getFilterLogs(String id); @Override Object[] eth_getLogs(FilterRequest fr); @Override Map<String, String> rpc_modules(); @Override void db_putString(); @Override void db_getString(); @Override boolean eth_submitWork(String nonce, String header, String mince); @Override boolean eth_submitHashrate(String hashrate, String id); @Override void db_putHex(); @Override void db_getHex(); @Override String personal_newAccountWithSeed(String seed); @Override String personal_newAccount(String passphrase); @Override String personal_importRawKey(String key, String passphrase); @Override String personal_dumpRawKey(String address); @Override String[] personal_listAccounts(); @Override String personal_sendTransaction(CallArguments args, String passphrase); @Override boolean personal_unlockAccount(String address, String passphrase, String duration); @Override boolean personal_lockAccount(String address); @Override EthModule getEthModule(); @Override EvmModule getEvmModule(); @Override TxPoolModule getTxPoolModule(); @Override MnrModule getMnrModule(); @Override DebugModule getDebugModule(); @Override TraceModule getTraceModule(); @Override RskModule getRskModule(); @Override void sco_banAddress(String address); @Override void sco_unbanAddress(String address); @Override PeerScoringInformation[] sco_peerList(); @Override String[] sco_bannedAddresses(); public Ethereum eth; }
|
@Test public void testIsRelease() { NetworkParameters params = RegTestParams.get(); BridgeRegTestConstants bridgeConstants = BridgeRegTestConstants.getInstance(); Federation federation = bridgeConstants.getGenesisFederation(); List<BtcECKey> federationPrivateKeys = BridgeRegTestConstants.REGTEST_FEDERATION_PRIVATE_KEYS; Address randomAddress = new Address(params, Hex.decode("4a22c3c4cbb31e4d03b15550636762bda0baf85a")); BtcTransaction releaseTx1 = new BtcTransaction(params); releaseTx1.addOutput(Coin.COIN, randomAddress); TransactionInput releaseInput1 = new TransactionInput(params, releaseTx1, new byte[]{}, new TransactionOutPoint(params, 0, Sha256Hash.ZERO_HASH)); releaseTx1.addInput(releaseInput1); signWithNecessaryKeys(federation, federationPrivateKeys, releaseInput1, releaseTx1, bridgeConstants); assertThat(BridgeUtils.isReleaseTx(releaseTx1, Collections.singletonList(federation)), is(true)); BtcTransaction releaseTx2 = new BtcTransaction(params); releaseTx2.addOutput(Coin.COIN, randomAddress); TransactionInput releaseInput2 = new TransactionInput(params, releaseTx2, new byte[]{}, new TransactionOutPoint(params, 0, Sha256Hash.ZERO_HASH)); releaseTx2.addInput(releaseInput2); signWithNKeys(federation, federationPrivateKeys, releaseInput2, releaseTx2, bridgeConstants, 1); assertThat(BridgeUtils.isReleaseTx(releaseTx2, Collections.singletonList(federation)), is(false)); }
|
private static boolean isReleaseTx(BtcTransaction tx, Federation federation) { return isReleaseTx(tx, Collections.singletonList(federation)); }
|
BridgeUtils { private static boolean isReleaseTx(BtcTransaction tx, Federation federation) { return isReleaseTx(tx, Collections.singletonList(federation)); } }
|
BridgeUtils { private static boolean isReleaseTx(BtcTransaction tx, Federation federation) { return isReleaseTx(tx, Collections.singletonList(federation)); } }
|
BridgeUtils { private static boolean isReleaseTx(BtcTransaction tx, Federation federation) { return isReleaseTx(tx, Collections.singletonList(federation)); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { private static boolean isReleaseTx(BtcTransaction tx, Federation federation) { return isReleaseTx(tx, Collections.singletonList(federation)); } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void testIsContractTx() { Assert.assertFalse(BridgeUtils.isContractTx(new Transaction((byte[]) null, null, null, null, null, null))); Assert.assertTrue(BridgeUtils.isContractTx(new org.ethereum.vm.program.InternalTransaction(null, 0, 0, null, null, null, null, null, null, null, null))); }
|
public static boolean isContractTx(Transaction rskTx) { return rskTx.getClass() == org.ethereum.vm.program.InternalTransaction.class; }
|
BridgeUtils { public static boolean isContractTx(Transaction rskTx) { return rskTx.getClass() == org.ethereum.vm.program.InternalTransaction.class; } }
|
BridgeUtils { public static boolean isContractTx(Transaction rskTx) { return rskTx.getClass() == org.ethereum.vm.program.InternalTransaction.class; } }
|
BridgeUtils { public static boolean isContractTx(Transaction rskTx) { return rskTx.getClass() == org.ethereum.vm.program.InternalTransaction.class; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean isContractTx(Transaction rskTx) { return rskTx.getClass() == org.ethereum.vm.program.InternalTransaction.class; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test(expected = BridgeIllegalArgumentException.class) public void getCoinFromBigInteger_bigger_than_long_value() { BridgeUtils.getCoinFromBigInteger(new BigInteger("9223372036854775808")); }
|
public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test(expected = BridgeIllegalArgumentException.class) public void getCoinFromBigInteger_null_value() { BridgeUtils.getCoinFromBigInteger(null); }
|
public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void getCoinFromBigInteger() { Assert.assertEquals(Coin.COIN, BridgeUtils.getCoinFromBigInteger(BigInteger.valueOf(Coin.COIN.getValue()))); }
|
public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static Coin getCoinFromBigInteger(BigInteger value) { if (value == null) { throw new BridgeIllegalArgumentException("value cannot be null"); } try { return Coin.valueOf(value.longValueExact()); } catch(ArithmeticException e) { throw new BridgeIllegalArgumentException(e.getMessage(), e); } } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test(expected = Exception.class) public void validateHeightAndConfirmations_invalid_height() throws Exception { Assert.assertFalse(BridgeUtils.validateHeightAndConfirmations(-1, 0, 0, null)); }
|
public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void validateHeightAndConfirmation_insufficient_confirmations() throws Exception { Assert.assertFalse(BridgeUtils.validateHeightAndConfirmations(2, 5, 10, Sha256Hash.of(Hex.decode("ab")))); }
|
public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
@Test public void validateHeightAndConfirmation_enough_confirmations() throws Exception { Assert.assertTrue(BridgeUtils.validateHeightAndConfirmations(2, 5, 3, Sha256Hash.of(Hex.decode("ab")))); }
|
public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
BridgeUtils { public static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash) throws Exception { if (height < 0) { throw new Exception("Height can't be lower than 0"); } int confirmations = btcBestChainHeight - height + 1; if (confirmations < acceptableConfirmationsAmount) { logger.warn( "Btc Tx {} at least {} confirmations are required, but there are only {} confirmations", btcTxHash, acceptableConfirmationsAmount, confirmations ); return false; } return true; } static Wallet getFederationNoSpendWallet(Context btcContext, Federation federation); static Wallet getFederationsNoSpendWallet(Context btcContext, List<Federation> federations); static Wallet getFederationSpendWallet(Context btcContext, Federation federation, List<UTXO> utxos); static Wallet getFederationsSpendWallet(Context btcContext, List<Federation> federations, List<UTXO> utxos); static boolean isValidLockTx(BtcTransaction tx); static Optional<Script> getFirstInputScriptSig(BtcTransaction tx); static boolean isLockTx(BtcTransaction tx, List<Federation> federations, Context btcContext, BridgeConstants bridgeConstants); static boolean isLockTx(BtcTransaction tx, Federation federation, Context btcContext, BridgeConstants bridgeConstants); static boolean txIsProcessable(BtcLockSender.TxType txType, ActivationConfig.ForBlock activations); static boolean isReleaseTx(BtcTransaction tx, List<Federation> federations); static boolean isMigrationTx(BtcTransaction btcTx, Federation activeFederation, Federation retiringFederation, Context btcContext, BridgeConstants bridgeConstants); static int countMissingSignatures(Context btcContext, BtcTransaction btcTx); static boolean hasEnoughSignatures(Context btcContext, BtcTransaction btcTx); static Address recoverBtcAddressFromEthTransaction(org.ethereum.core.Transaction tx, NetworkParameters networkParameters); static boolean isFreeBridgeTx(Transaction rskTx, Constants constants, ActivationConfig.ForBlock activations); static boolean isContractTx(Transaction rskTx); static boolean isFromFederateMember(org.ethereum.core.Transaction rskTx, Federation federation); static Coin getCoinFromBigInteger(BigInteger value); static boolean validateHeightAndConfirmations(int height, int btcBestChainHeight, int acceptableConfirmationsAmount, Sha256Hash btcTxHash); static Sha256Hash calculateMerkleRoot(NetworkParameters networkParameters, byte[] pmtSerialized, Sha256Hash btcTxHash); static void validateInputsCount(byte[] btcTxSerialized, boolean isActiveRskip); static boolean isInputSignedByThisFederator(BtcECKey federatorPublicKey, Sha256Hash sighash, TransactionInput input); }
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.