tech.pegasys.pantheon.ethereum.core.Address.extract()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中tech.pegasys.pantheon.ethereum.core.Address.extract()方法的一些代码示例,展示了Address.extract()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Address.extract()方法的具体详情如下:
包路径:tech.pegasys.pantheon.ethereum.core.Address
类名称:Address
方法名:extract

Address.extract介绍

暂无

代码示例

代码示例来源:origin: PegaSysEng/pantheon

public String getAddress() {
 return Address.extract(Hash.hash(keyPair.getPublicKey().getEncodedBytes())).toString();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void insufficientCommitSealsFailsValidation() {
 final KeyPair committerKeyPair = KeyPair.generate();
 final Address committerAddress =
   Address.extract(Hash.hash(committerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = singletonList(committerAddress);
 final VoteTally voteTally = new VoteTally(validators);
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final BlockHeader header = createProposedBlockHeader(validators, emptyList(), false);
 // Note that no committer seals are in the header's IBFT extra data.
 final IbftExtraData headerExtraData = IbftExtraData.decode(header.getExtraData());
 assertThat(headerExtraData.getSeals().size()).isEqualTo(0);
 assertThat(commitSealsValidationRule.validate(header, null, context)).isFalse();
}

代码示例来源:origin: PegaSysEng/pantheon

private boolean subExecution(
   final int validatorCount,
   final int committerCount,
   final boolean useDifferentRoundNumbersForCommittedSeals) {

  final List<Address> validators = Lists.newArrayList();
  final List<KeyPair> committerKeys = Lists.newArrayList();

  for (int i = 0; i < validatorCount; i++) { // need -1 to account for proposer
   final KeyPair committerKeyPair = KeyPair.generate();
   committerKeys.add(committerKeyPair);
   validators.add(Address.extract(Hash.hash(committerKeyPair.getPublicKey().getEncodedBytes())));
  }

  Collections.sort(validators);
  final VoteTally voteTally = new VoteTally(validators);
  BlockHeader header =
    createProposedBlockHeader(
      validators,
      committerKeys.subList(0, committerCount),
      useDifferentRoundNumbersForCommittedSeals);

  final ProtocolContext<IbftContext> context =
    new ProtocolContext<>(null, null, new IbftContext(voteTally, null));

  return commitSealsValidationRule.validate(header, null, context);
 }
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void proposerInValidatorListPassesValidation() {
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = Lists.newArrayList(proposerAddress);
 final List<KeyPair> committers = Lists.newArrayList(proposerKeyPair);
 final VoteTally voteTally = new VoteTally(validators);
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final IbftCoinbaseValidationRule coinbaseValidationRule = new IbftCoinbaseValidationRule();
 BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators, committers);
 assertThat(coinbaseValidationRule.validate(header, null, context)).isTrue();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void ibftValidateHeaderPasses() {
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = singletonList(proposerAddress);
 final BlockHeader parentHeader = buildBlockHeader(1, proposerKeyPair, validators, null);
 final BlockHeader blockHeader = buildBlockHeader(2, proposerKeyPair, validators, parentHeader);
 final BlockHeaderValidator<IbftContext> validator =
   IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5);
 assertThat(
     validator.validateHeader(
       blockHeader,
       parentHeader,
       IbftProtocolContextFixture.protocolContext(validators),
       HeaderValidationMode.FULL))
   .isTrue();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void ibftValidateHeaderFails() {
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = singletonList(proposerAddress);
 final BlockHeader parentHeader = buildBlockHeader(1, proposerKeyPair, validators, null);
 final BlockHeader blockHeader = buildBlockHeader(2, proposerKeyPair, validators, null);
 final BlockHeaderValidator<IbftContext> validator =
   IbftBlockHeaderValidationRulesetFactory.ibftBlockHeaderValidator(5);
 assertThat(
     validator.validateHeader(
       blockHeader,
       parentHeader,
       IbftProtocolContextFixture.protocolContext(validators),
       HeaderValidationMode.FULL))
   .isFalse();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
 public void proposerNotInValidatorListFailsValidation() {
  final KeyPair proposerKeyPair = KeyPair.generate();

  final KeyPair otherValidatorKeyPair = KeyPair.generate();
  final Address otherValidatorNodeAddress =
    Address.extract(Hash.hash(otherValidatorKeyPair.getPublicKey().getEncodedBytes()));

  final List<Address> validators = Lists.newArrayList(otherValidatorNodeAddress);

  final List<KeyPair> committers = Lists.newArrayList(otherValidatorKeyPair);

  final VoteTally voteTally = new VoteTally(validators);
  final ProtocolContext<IbftContext> context =
    new ProtocolContext<>(null, null, new IbftContext(voteTally, null));

  final IbftCoinbaseValidationRule coinbaseValidationRule = new IbftCoinbaseValidationRule();

  BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators, committers);

  assertThat(coinbaseValidationRule.validate(header, null, context)).isFalse();
 }
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void insufficientCommitSealsFailsValidation() {
 final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
 builder.number(1); // must NOT be block 0, as that should not contain seals at all
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = singletonList(proposerAddress);
 final VoteTally voteTally = new VoteTally(validators);
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final IbftExtraDataValidationRule extraDataValidationRule =
   new IbftExtraDataValidationRule(true);
 final BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
 // Note that no committer seals are in the header's IBFT extra data.
 final IbftExtraData headerExtraData = IbftExtraData.decode(header.getExtraData());
 Assertions.assertThat(headerExtraData.getSeals().size()).isEqualTo(0);
 assertThat(extraDataValidationRule.validate(header, null, context)).isFalse();
}

代码示例来源:origin: PegaSysEng/pantheon

Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
final KeyPair committerKeyPair = KeyPair.generate();
committerKeys.add(committerKeyPair);
validators.add(Address.extract(Hash.hash(committerKeyPair.getPublicKey().getEncodedBytes())));

代码示例来源:origin: PegaSysEng/pantheon

final Address localAddr = Address.extract(Hash.hash(nodeKeys.getPublicKey().getEncodedBytes()));
final List<Address> initialValidatorList =
  Arrays.asList(

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void mismatchingReportedValidatorsVsLocallyStoredListFailsValidation() {
 final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
 builder.number(1); // must NOT be block 0, as that should not contain seals at all
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = Lists.newArrayList(proposerAddress);
 final VoteTally voteTally = new VoteTally(validators);
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final IbftExtraDataValidationRule extraDataValidationRule =
   new IbftExtraDataValidationRule(true);
 // Add another validator to the list reported in the IbftExtraData (note, as the
 validators.add(AddressHelpers.calculateAddressWithRespectTo(proposerAddress, 1));
 BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
 // Insert an extraData block with committer seals.
 final IbftExtraData commitedExtraData =
   createExtraDataWithCommitSeals(header, singletonList(proposerKeyPair));
 builder.extraData(commitedExtraData.encode());
 header = builder.buildHeader();
 assertThat(extraDataValidationRule.validate(header, null, context)).isFalse();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void correctlyConstructedHeaderPassesValidation() {
 final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
 builder.number(1); // must NOT be block 0, as that should not contain seals at all
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = singletonList(proposerAddress);
 final VoteTally voteTally = new VoteTally(validators);
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final IbftExtraDataValidationRule extraDataValidationRule =
   new IbftExtraDataValidationRule(true);
 BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
 // Insert an extraData block with committer seals.
 final IbftExtraData commitedExtraData =
   createExtraDataWithCommitSeals(header, singletonList(proposerKeyPair));
 builder.extraData(commitedExtraData.encode());
 header = builder.buildHeader();
 assertThat(extraDataValidationRule.validate(header, null, context)).isTrue();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void committerNotInValidatorListFailsValidation() {
 final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
 builder.number(1); // must NOT be block 0, as that should not contain seals at all
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators = singletonList(proposerAddress);
 final VoteTally voteTally = new VoteTally(validators);
 BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
 // Insert an extraData block with committer seals.
 final KeyPair nonValidatorKeyPair = KeyPair.generate();
 final IbftExtraData commitedExtraData =
   createExtraDataWithCommitSeals(header, singletonList(nonValidatorKeyPair));
 builder.extraData(commitedExtraData.encode());
 header = builder.buildHeader();
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final IbftExtraDataValidationRule extraDataValidationRule =
   new IbftExtraDataValidationRule(true);
 assertThat(extraDataValidationRule.validate(header, null, context)).isFalse();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void outOfOrderValidatorListFailsValidation() {
 final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
 builder.number(1); // must NOT be block 0, as that should not contain seals at all
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators =
   Lists.newArrayList(
     AddressHelpers.calculateAddressWithRespectTo(proposerAddress, 1), proposerAddress);
 final VoteTally voteTally = new VoteTally(validators);
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final IbftExtraDataValidationRule extraDataValidationRule =
   new IbftExtraDataValidationRule(true);
 BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
 // Insert an extraData block with committer seals.
 final IbftExtraData commitedExtraData =
   createExtraDataWithCommitSeals(header, singletonList(proposerKeyPair));
 builder.extraData(commitedExtraData.encode());
 header = builder.buildHeader();
 assertThat(extraDataValidationRule.validate(header, null, context)).isFalse();
}

代码示例来源:origin: PegaSysEng/pantheon

@Test
public void proposerNotInValidatorListFailsValidation() {
 final BlockHeaderTestFixture builder = new BlockHeaderTestFixture();
 builder.number(1); // must NOT be block 0, as that should not contain seals at all
 final KeyPair proposerKeyPair = KeyPair.generate();
 final Address proposerAddress =
   Address.extract(Hash.hash(proposerKeyPair.getPublicKey().getEncodedBytes()));
 final List<Address> validators =
   Lists.newArrayList(
     AddressHelpers.calculateAddressWithRespectTo(proposerAddress, 1), proposerAddress);
 final VoteTally voteTally = new VoteTally(validators);
 final ProtocolContext<IbftContext> context =
   new ProtocolContext<>(null, null, new IbftContext(voteTally, null));
 final IbftExtraDataValidationRule extraDataValidationRule =
   new IbftExtraDataValidationRule(true);
 BlockHeader header = createProposedBlockHeader(proposerKeyPair, validators);
 // Insert an extraData block with committer seals.
 final IbftExtraData commitedExtraData =
   createExtraDataWithCommitSeals(header, singletonList(proposerKeyPair));
 builder.extraData(commitedExtraData.encode());
 header = builder.buildHeader();
 assertThat(extraDataValidationRule.validate(header, null, context)).isFalse();
}

相关文章