use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMain method doCost.
private static void doCost() throws IOException {
List<String> sources = new ArrayList<String>((List) options.valuesOf("cost"));
// if command use as key for -register command
List<String> registerSources = new ArrayList<String>((List) options.valuesOf("register"));
for (String opt : registerSources) {
sources.addAll(asList(opt.split(",")));
}
List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments());
for (String opt : nonOptions) {
sources.addAll(asList(opt.split(",")));
}
cleanNonOptionalArguments(sources);
for (int s = 0; s < sources.size(); s++) {
String source = sources.get(s);
ContractFileTypes fileType = getFileType(source);
report("");
report("Calculating cost of " + source + ", type is " + fileType + "...");
// Here should repeat procedure of contract processi on the Node
// (Contract.fromPackedTransaction() -> Contract(byte[], TransactionPack) -> Contract.check() -> Contract.getNewItems.check())
Contract contract = null;
if (fileType == ContractFileTypes.BINARY) {
contract = loadContract(source);
} else {
// contract = Contract.fromPackedTransaction(importContract(source).getPackedTransaction());
addError(Errors.COMMAND_FAILED.name(), source, "Contract should be sealed binary");
}
if (contract != null) {
try {
contract.check();
} catch (Quantiser.QuantiserException e) {
addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage());
}
// addErrors(contract.getErrors());
// if (contract.getErrors().size() == 0) {
// report("Contract is valid");
// }
printProcessingCost(contract);
}
}
finish();
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMain method doPackWith.
private static void doPackWith() throws IOException {
List<String> sources = new ArrayList<String>((List) options.valuesOf("pack-with"));
List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments());
for (String opt : nonOptions) {
sources.addAll(asList(opt.split(",")));
}
cleanNonOptionalArguments(sources);
List siblingItems = options.valuesOf("add-sibling");
List revokeItems = options.valuesOf("add-revoke");
List<String> names = (List) options.valuesOf("name");
for (int s = 0; s < sources.size(); s++) {
String source = sources.get(s);
String name = null;
if (names.size() > s)
name = names.get(s);
Contract contract = loadContract(source, true);
try {
if (contract != null) {
if (contract.check()) {
report("pack contract from " + source);
if (siblingItems != null) {
for (Object sibFile : siblingItems) {
Contract siblingContract = loadContract((String) sibFile, true);
report("add sibling from " + sibFile);
contract.addNewItems(siblingContract);
}
}
if (revokeItems != null) {
for (Object revokeFile : revokeItems) {
Contract revokeContract = loadContract((String) revokeFile, true);
report("add revoke from " + revokeFile);
contract.addRevokingItems(revokeContract);
}
}
if (name == null) {
name = source;
}
if (siblingItems != null || revokeItems != null) {
contract.seal();
saveContract(contract, name, true, true);
}
} else {
addErrors(contract.getErrors());
}
}
} catch (Quantiser.QuantiserException e) {
addError("QUANTIZER_COST_LIMIT", contract.toString(), e.getMessage());
}
}
finish();
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMain method revokeContract.
/**
* Revoke specified contract and create a revocation transactional contract.
*
* @param contract
*
* @return Contract - revoking transaction contract.
*/
@Deprecated
public static Contract revokeContract(Contract contract, PrivateKey... key) throws IOException {
report("keys num: " + key.length);
Contract tc = ContractsService.createRevocation(contract, key);
registerContract(tc, 0, true);
return tc;
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMain method doExport.
private static void doExport() throws IOException {
List<String> sources = new ArrayList<String>((List) options.valuesOf("e"));
List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments());
for (String opt : nonOptions) {
sources.addAll(asList(opt.split(",")));
}
cleanNonOptionalArguments(sources);
List<String> formats = new ArrayList<String>((List) options.valuesOf("as"));
List<String> names = (List) options.valuesOf("name");
List<String> extractKeyRoles = (List) options.valuesOf("extract-key");
List extractFields = options.valuesOf("get");
List updateFields = options.valuesOf("set");
List updateValues = options.valuesOf("value");
for (int s = 0; s < sources.size(); s++) {
String source = sources.get(s);
String name = null;
String format = "json";
if (names.size() > s) {
name = names.get(s);
String extension = "";
int i = name.lastIndexOf('.');
if (i > 0) {
extension = name.substring(i + 1).toLowerCase();
}
switch(extension) {
case "json":
case "xml":
case "yaml":
case "yml":
format = extension;
}
}
if (formats.size() > s)
format = formats.get(s);
else if (formats.size() == 1)
format = formats.get(0);
HashMap<String, String> updateFieldsHashMap = new HashMap<>();
Contract contract = loadContract(source);
if (contract != null) {
try {
for (int i = 0; i < updateFields.size(); i++) {
updateFieldsHashMap.put((String) updateFields.get(i), (String) updateValues.get(i));
}
} catch (Exception e) {
}
if (updateFieldsHashMap.size() > 0) {
updateFields(contract, updateFieldsHashMap);
}
if (extractKeyRoles != null && extractKeyRoles.size() > 0) {
String extractKeyRole;
for (int i = 0; i < extractKeyRoles.size(); i++) {
extractKeyRole = extractKeyRoles.get(i);
if (name == null) {
name = source.replaceAll("(?i)\\.(unicon)$", ".pub");
}
exportPublicKeys(contract, extractKeyRole, name, options.has("base64"));
}
} else if (extractFields != null && extractFields.size() > 0) {
if (name == null) {
name = source.replaceAll("(?i)\\.(unicon)$", "_fields." + format);
}
exportFields(contract, extractFields, name, format, options.has("pretty"));
} else {
if (name == null) {
name = source.replaceAll("(?i)\\.(unicon)$", "." + format);
}
exportContract(contract, name, format, options.has("pretty"));
}
}
}
finish();
}
use of com.icodici.universa.contract.Contract in project universa by UniversaBlockchain.
the class CLIMain method doAnonymize.
private static void doAnonymize() throws IOException {
List<String> sources = new ArrayList<String>((List) options.valuesOf("anonymize"));
List<String> roles = new ArrayList<String>((List) options.valuesOf("role"));
List<String> names = (List) options.valuesOf("name");
List<String> nonOptions = new ArrayList<String>((List) options.nonOptionArguments());
for (String opt : nonOptions) {
sources.addAll(asList(opt.split(",")));
}
cleanNonOptionalArguments(sources);
for (int s = 0; s < sources.size(); s++) {
String source = sources.get(s);
Contract contract = loadContract(source);
if (contract != null) {
if (roles.size() <= 0) {
roles = new ArrayList<>(contract.getRoles().keySet());
}
for (String roleName : roles) {
report("Anonymizing role " + roleName + " in " + source + "...");
contract.anonymizeRole(roleName);
contract.seal();
}
if (names.size() > s) {
saveContract(contract, names.get(s), true, false);
} else {
saveContract(contract, source.replaceAll("(?i)\\.(unicon)$", "_anonymized.unicon"), true, false);
}
}
}
finish();
}
Aggregations