Search in sources :

Example 1 with FEE_SCHEDULE_FILE_PART_UPLOADED

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.FEE_SCHEDULE_FILE_PART_UPLOADED 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;
            }
        }
    }));
}
Also used : KeyPair(java.security.KeyPair) Arrays(java.util.Arrays) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) Base64(org.apache.commons.codec.binary.Base64) CommonUtils(com.hedera.services.legacy.proto.utils.CommonUtils) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) Map(java.util.Map) SplittableRandom(java.util.SplittableRandom) Path(java.nio.file.Path) EnumSet(java.util.EnumSet) EnumMap(java.util.EnumMap) CurrentAndNextFeeSchedule(com.hederahashgraph.api.proto.java.CurrentAndNextFeeSchedule) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) HapiApiSpec.customHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.customHapiSpec) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) ExchangeRateSet(com.hederahashgraph.api.proto.java.ExchangeRateSet) Optional(java.util.Optional) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) Pattern(java.util.regex.Pattern) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) Ed25519KeyStore(com.hedera.services.bdd.suites.utils.keypairs.Ed25519KeyStore) KeyPairObj(com.hedera.services.legacy.core.KeyPairObj) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) Function(java.util.function.Function) Setting(com.hederahashgraph.api.proto.java.Setting) UtilVerbs.keyFromPem(com.hedera.services.bdd.spec.utilops.UtilVerbs.keyFromPem) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) CustomSpecAssert(com.hedera.services.bdd.spec.utilops.CustomSpecAssert) Charset(java.nio.charset.Charset) Files(com.google.common.io.Files) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) FeesJsonToProtoSerde(com.hedera.services.sysfiles.serdes.FeesJsonToProtoSerde) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) ObjectOutputStream(java.io.ObjectOutputStream) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) Properties(java.util.Properties) FEE_SCHEDULE_FILE_PART_UPLOADED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FEE_SCHEDULE_FILE_PART_UPLOADED) BufferedWriter(java.io.BufferedWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) JutilPropsToSvcCfgBytes(com.hedera.services.bdd.suites.utils.sysfiles.serdes.JutilPropsToSvcCfgBytes) PropertySource.asAccount(com.hedera.services.bdd.spec.PropertySource.asAccount) SpecUtils(com.hedera.services.bdd.suites.utils.keypairs.SpecUtils) File(java.io.File) Key(com.hederahashgraph.api.proto.java.Key) Paths(java.nio.file.Paths) LogManager(org.apache.logging.log4j.LogManager) AccountKeyListObj(com.hedera.services.legacy.core.AccountKeyListObj) ByteString(com.google.protobuf.ByteString) Properties(java.util.Properties) IOException(java.io.IOException) ServicesConfigurationList(com.hederahashgraph.api.proto.java.ServicesConfigurationList) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) File(java.io.File)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Files (com.google.common.io.Files)1 ByteString (com.google.protobuf.ByteString)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiApiSpec.customHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.customHapiSpec)1 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)1 PropertySource.asAccount (com.hedera.services.bdd.spec.PropertySource.asAccount)1 KeyFactory (com.hedera.services.bdd.spec.keys.KeyFactory)1 QueryVerbs.getFileContents (com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents)1 QueryVerbs.getFileInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 TxnVerbs.cryptoUpdate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate)1 TxnVerbs.fileAppend (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend)1 TxnVerbs.fileUpdate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate)1 CustomSpecAssert (com.hedera.services.bdd.spec.utilops.CustomSpecAssert)1 UtilVerbs.keyFromPem (com.hedera.services.bdd.spec.utilops.UtilVerbs.keyFromPem)1 UtilVerbs.newKeyNamed (com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed)1 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)1 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)1 Ed25519KeyStore (com.hedera.services.bdd.suites.utils.keypairs.Ed25519KeyStore)1