use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class NewSpecKeyList method submitOp.
@Override
protected boolean submitOp(HapiApiSpec spec) throws Throwable {
List<Key> childKeys = keys.stream().map(spec.registry()::getKey).collect(toList());
Key newList = Key.newBuilder().setKeyList(KeyList.newBuilder().addAllKeys(childKeys)).build();
spec.registry().saveKey(name, newList);
SigControl[] childControls = childKeys.stream().map(spec.keys()::controlFor).toArray(SigControl[]::new);
spec.keys().setControl(newList, SigControl.listSigs(childControls));
return false;
}
use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class ValidationScenarios method parse.
private static void parse(String[] args) {
var KEY_VALUE_PATTERN = Pattern.compile("([\\w\\d]+)=([\\w\\d,.-]+)");
for (String arg : args) {
var matcher = KEY_VALUE_PATTERN.matcher(arg);
if (!matcher.matches()) {
log.warn(String.format("Ignoring command-line argument '%s'", arg));
} else {
if ("target".equals(keyOf(matcher))) {
params.setTargetNetwork(valueOf(matcher));
} else if ("defaultNodePayment".equals(keyOf(matcher))) {
try {
params.setDefaultNodePayment(Long.parseLong(valueOf(matcher)));
} catch (NumberFormatException ignore) {
}
} else if ("novel".equals(keyOf(matcher))) {
params.setNovelContent(valueOf(matcher).toLowerCase().equals("true"));
} else if ("revocation".equals(keyOf(matcher))) {
params.setRevocationService(valueOf(matcher).toLowerCase().equals("true"));
} else if ("scenarios".equals(keyOf(matcher))) {
Set<String> legal = Arrays.stream(Scenario.class.getEnumConstants()).map(Object::toString).collect(Collectors.toSet());
List<String> listed = Arrays.stream(valueOf(matcher).split(",")).map(name -> name.equals("fees") ? "FEE_SNAPSHOTS" : name).map(name -> name.equals("syskeys") ? "SYSTEM_KEYS" : name).map(name -> name.equals("xfers") ? "TRANSFERS_ONLY" : name).map(name -> name.equals("sysFilesDown") ? "SYS_FILES_DOWN" : name).map(name -> name.equals("sysFilesUp") ? "SYS_FILES_UP" : name).filter(v -> legal.contains(v.toUpperCase())).collect(toList());
if (listed.size() == 1) {
params.setScenarios(EnumSet.of(Scenario.valueOf(listed.get(0).toUpperCase())));
} else if (listed.size() > 1) {
params.setScenarios(EnumSet.of(Scenario.valueOf(listed.get(0).toUpperCase()), listed.subList(1, listed.size()).stream().map(String::toUpperCase).map(Scenario::valueOf).toArray(n -> new Scenario[n])));
}
} else if ("config".equals(keyOf(matcher))) {
params.setConfigLoc(valueOf(matcher));
} else {
log.warn(String.format("Ignoring unknown parameter key '%s'", keyOf(matcher)));
}
}
}
System.out.println(params.getScenarios());
}
use of com.hederahashgraph.api.proto.java.Key in project hedera-services by hashgraph.
the class SysFilesUpdate method updateTargetFromHumanReadable.
private HapiApiSpec updateTargetFromHumanReadable() {
byte[] bytes = new byte[0];
String nodesOverride = envNodes();
System.out.println("Targeting " + nodesOverride);
String loc = humanReadableFileNames.get(target);
String readableFile = qualifiedPath(nodesOverride, loc, false);
try {
if (BOOK_FILES.contains(target)) {
AddressBookPojo pojoBook = mapper.readValue(new File(readableFile), AddressBookPojo.class);
var addressBook = NodeAddressBook.newBuilder();
pojoBook.getEntries().stream().flatMap(updateConverters.get(target)).forEach(addressBook::addNodeAddress);
bytes = addressBook.build().toByteArray();
} else if (target == SystemFile.EXCHANGE_RATES) {
var pojoRates = mapper.readValue(new File(readableFile), ExchangeRatesPojo.class);
bytes = pojoRates.toProto().toByteArray();
} else if (target == SystemFile.FEE_SCHEDULE) {
final var literal = java.nio.file.Files.readString(Paths.get(readableFile));
bytes = FeesJsonToProtoSerde.parseFeeScheduleFromJson(literal).toByteArray();
} else {
var jutilConfig = new Properties();
jutilConfig.load(java.nio.file.Files.newInputStream(Paths.get(readableFile)));
ServicesConfigurationList.Builder protoConfig = ServicesConfigurationList.newBuilder();
jutilConfig.stringPropertyNames().stream().sorted(JutilPropsToSvcCfgBytes.LEGACY_THROTTLES_FIRST_ORDER).forEach(prop -> protoConfig.addNameValue(Setting.newBuilder().setName(prop).setValue(jutilConfig.getProperty(prop))));
bytes = protoConfig.build().toByteArray();
}
} catch (Exception e) {
System.out.println(String.format("File '%s' should contain a human-readable %s representation!", readableFile, target.toString()));
e.printStackTrace();
System.exit(1);
}
final byte[] toUpload = bytes;
return customHapiSpec(String.format("Update-%s-FromHumanReadable", target)).withProperties(Map.of("nodes", nodesOverride, "default.payer", defaultPayerOverride, "startupAccounts.path", startupAccountsPathOverride)).given(withOpContext((spec, opLog) -> {
var sysFileOcKeystore = SpecUtils.asOcKeystore(new File(DEFAULT_SYSFILE_PEM_LOC), KeyFactory.PEM_PASSPHRASE);
var sysFileKey = Key.newBuilder().setEd25519(ByteString.copyFrom(com.swirlds.common.CommonUtils.unhex(sysFileOcKeystore.getPublicKeyAbyteStr()))).build();
opLog.info("Will ensure default public key :: " + sysFileKey + " (hex = " + sysFileOcKeystore.getPublicKeyAbyteStr() + ")");
spec.registry().saveKey(DEFAULT_SYSFILE_KEY, sysFileKey);
spec.keys().incorporate(DEFAULT_SYSFILE_KEY, sysFileOcKeystore);
}), keyFromPem(DEFAULT_SYSFILE_PEM_LOC).name("insurance").simpleWacl().passphrase(KeyFactory.PEM_PASSPHRASE)).when().then(withOpContext((spec, opLog) -> {
if (toUpload.length < (6 * 1024)) {
var singleOp = fileUpdate(registryNames.get(target)).payingWith(DEFAULT_PAYER).fee(feeToOffer()).contents(toUpload).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY);
CustomSpecAssert.allRunFor(spec, singleOp);
} else {
int n = 0;
while (n < toUpload.length) {
int thisChunkSize = Math.min(toUpload.length - n, 4096);
byte[] thisChunk = Arrays.copyOfRange(toUpload, n, n + thisChunkSize);
HapiSpecOperation subOp;
if (n == 0) {
subOp = fileUpdate(registryNames.get(target)).fee(feeToOffer()).wacl("insurance").contents(thisChunk).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED);
} else {
subOp = fileAppend(registryNames.get(target)).fee(feeToOffer()).content(thisChunk).signedBy(DEFAULT_PAYER, DEFAULT_SYSFILE_KEY).hasKnownStatusFrom(SUCCESS, FEE_SCHEDULE_FILE_PART_UPLOADED);
}
CustomSpecAssert.allRunFor(spec, subOp);
n += thisChunkSize;
}
}
}));
}
Aggregations