Search in sources :

Example 6 with WitnessCapsule

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());
}
Also used : WitnessCapsule(org.tron.core.capsule.WitnessCapsule) Test(org.junit.Test)

Example 7 with WitnessCapsule

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());
}
Also used : WitnessCapsule(org.tron.core.capsule.WitnessCapsule)

Example 8 with WitnessCapsule

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;
}
Also used : WitnessCapsule(org.tron.core.capsule.WitnessCapsule)

Example 9 with WitnessCapsule

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;
}
Also used : WitnessCapsule(org.tron.core.capsule.WitnessCapsule)

Example 10 with WitnessCapsule

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);
    }
}
Also used : AccountCapsule(org.tron.core.capsule.AccountCapsule) WitnessCapsule(org.tron.core.capsule.WitnessCapsule) BalanceInsufficientException(org.tron.core.exception.BalanceInsufficientException)

Aggregations

WitnessCapsule (org.tron.core.capsule.WitnessCapsule)13 ByteString (com.google.protobuf.ByteString)4 ECKey (org.tron.common.crypto.ECKey)3 AccountCapsule (org.tron.core.capsule.AccountCapsule)3 Test (org.junit.Test)2 BlockCapsule (org.tron.core.capsule.BlockCapsule)2 BalanceInsufficientException (org.tron.core.exception.BalanceInsufficientException)2 RamUsageEstimator (com.carrotsearch.sizeof.RamUsageEstimator)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Lock (java.util.concurrent.locks.Lock)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1