use of org.tron.core.capsule.WitnessCapsule in project java-tron by tronprotocol.
the class WitnessStoreTest method putAndGetWitness.
@Test
public void putAndGetWitness() {
WitnessCapsule witnessCapsule = new WitnessCapsule(ByteString.copyFromUtf8("100000000x"), 100L, "");
this.witnessStore.put(witnessCapsule.getAddress().toByteArray(), witnessCapsule);
WitnessCapsule witnessSource = this.witnessStore.get(ByteString.copyFromUtf8("100000000x").toByteArray());
Assert.assertEquals(witnessCapsule.getAddress(), witnessSource.getAddress());
Assert.assertEquals(witnessCapsule.getVoteCount(), witnessSource.getVoteCount());
Assert.assertEquals(ByteString.copyFromUtf8("100000000x"), witnessSource.getAddress());
Assert.assertEquals(100L, witnessSource.getVoteCount());
witnessCapsule = new WitnessCapsule(ByteString.copyFromUtf8(""), 100L, "");
this.witnessStore.put(witnessCapsule.getAddress().toByteArray(), witnessCapsule);
witnessSource = this.witnessStore.get(ByteString.copyFromUtf8("").toByteArray());
Assert.assertEquals(witnessCapsule.getAddress(), witnessSource.getAddress());
Assert.assertEquals(witnessCapsule.getVoteCount(), witnessSource.getVoteCount());
Assert.assertEquals(ByteString.copyFromUtf8(""), witnessSource.getAddress());
Assert.assertEquals(100L, witnessSource.getVoteCount());
}
use of org.tron.core.capsule.WitnessCapsule in project java-tron by tronprotocol.
the class AccountVoteWitnessTest method printWitness.
private void printWitness(final ByteString address) {
final WitnessCapsule witnessCapsule = dbManager.getWitnessStore().get(address.toByteArray());
if (null == witnessCapsule) {
logger.info("address is {} , winess is null", address.toStringUtf8());
return;
}
logger.info("address is {} ,countVote is {}", witnessCapsule.getAddress().toStringUtf8(), witnessCapsule.getVoteCount());
}
use of org.tron.core.capsule.WitnessCapsule in project java-tron by tronprotocol.
the class AccountVoteWitnessTest method getWitnessList.
private List<WitnessCapsule> getWitnessList() {
final List<WitnessCapsule> witnessCapsuleList = Lists.newArrayList();
final WitnessCapsule witnessTron = new WitnessCapsule(ByteString.copyFrom("00000000001".getBytes()), 0, "");
final WitnessCapsule witnessOlivier = new WitnessCapsule(ByteString.copyFrom("00000000003".getBytes()), 100, "");
final WitnessCapsule witnessVivider = new WitnessCapsule(ByteString.copyFrom("00000000005".getBytes()), 200, "");
final WitnessCapsule witnessSenaLiu = new WitnessCapsule(ByteString.copyFrom("00000000006".getBytes()), 300, "");
witnessCapsuleList.add(witnessTron);
witnessCapsuleList.add(witnessOlivier);
witnessCapsuleList.add(witnessVivider);
witnessCapsuleList.add(witnessSenaLiu);
return witnessCapsuleList;
}
use of org.tron.core.capsule.WitnessCapsule in project java-tron by tronprotocol.
the class RandomGeneratorTest method getWitnessList.
private List<WitnessCapsule> getWitnessList() {
final List<WitnessCapsule> witnessCapsuleList = Lists.newArrayList();
final WitnessCapsule witnessTron = new WitnessCapsule(ByteString.copyFrom("00000000001".getBytes()), 0, "");
final WitnessCapsule witnessOlivier = new WitnessCapsule(ByteString.copyFrom("00000000003".getBytes()), 100, "");
final WitnessCapsule witnessVivider = new WitnessCapsule(ByteString.copyFrom("00000000005".getBytes()), 200, "");
final WitnessCapsule witnessSenaLiu = new WitnessCapsule(ByteString.copyFrom("00000000006".getBytes()), 300, "");
witnessCapsuleList.add(witnessTron);
witnessCapsuleList.add(witnessOlivier);
witnessCapsuleList.add(witnessVivider);
witnessCapsuleList.add(witnessSenaLiu);
return witnessCapsuleList;
}
use of org.tron.core.capsule.WitnessCapsule in project java-tron by tronprotocol.
the class Manager method updateSignedWitness.
/**
* @param block the block update signed witness. set witness who signed block the 1. the latest
* block num 2. pay the trx to witness. 3. (TODO)the latest slot num.
*/
public void updateSignedWitness(BlockCapsule block) {
// TODO: add verification
WitnessCapsule witnessCapsule = witnessStore.get(block.getInstance().getBlockHeader().getRawData().getWitnessAddress().toByteArray());
long latestSlotNum = 0;
witnessCapsule.getInstance().toBuilder().setLatestBlockNum(block.getNum()).setLatestSlotNum(latestSlotNum).build();
AccountCapsule sun = accountStore.getSun();
try {
adjustBalance(sun.getAddress().toByteArray(), -WITNESS_PAY_PER_BLOCK);
} catch (BalanceInsufficientException e) {
}
try {
adjustBalance(witnessCapsule.getAddress().toByteArray(), WITNESS_PAY_PER_BLOCK);
} catch (BalanceInsufficientException e) {
logger.debug(e.getMessage(), e);
}
}
Aggregations