This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RLP encoding subcommand for at least ibftExtraData to be inserted in genesis file. There's only one encodable type for the moment, however the `--type` option is already there with a default value on this type. We'll add more possible types later if needed and the current type will remain the default one. The file output is optional and it writes to standard output by default, same for standard input or a file. Tests and doc change.
- Loading branch information
1 parent
a712bc6
commit 9d2a67c
Showing
10 changed files
with
605 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
pantheon/src/main/java/tech/pegasys/pantheon/cli/rlp/IbftExtraDataCLIAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.cli.rlp; | ||
|
||
import tech.pegasys.pantheon.consensus.ibft.IbftExtraData; | ||
import tech.pegasys.pantheon.ethereum.core.Address; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
/** | ||
* Adapter to convert a typed JSON to an IbftExtraData object This adapter handles the JSON to RLP | ||
* encoding | ||
*/ | ||
public class IbftExtraDataCLIAdapter implements JSONToRLP { | ||
|
||
@Override | ||
public BytesValue encode(final String json) throws IOException { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
TypeReference<Collection<String>> typeRef = new TypeReference<Collection<String>>() {}; | ||
Collection<String> validatorAddresse = mapper.readValue(json, typeRef); | ||
|
||
Collection<Address> addresses = | ||
validatorAddresse.stream().map(Address::fromHexString).collect(Collectors.toList()); | ||
|
||
return new IbftExtraData( | ||
BytesValue.wrap(new byte[32]), Collections.emptyList(), Optional.empty(), 0, addresses) | ||
.encode(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
pantheon/src/main/java/tech/pegasys/pantheon/cli/rlp/JSONToRLP.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.cli.rlp; | ||
|
||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import java.io.IOException; | ||
|
||
/** Behaviour of objects that can be encoded from JSON to RLP */ | ||
interface JSONToRLP { | ||
|
||
/** | ||
* Encodes the object into an RLP value. | ||
* | ||
* @return the RLP encoded object. | ||
*/ | ||
BytesValue encode(String json) throws IOException; | ||
} |
Oops, something went wrong.