public void setExtendedType(String extendedType) { this.extendedType = extendedType; if(definition != null) definition.set("extended_type", extendedType); } public String getExtendedType() {
public Binder serializeWith(BiSerializer serializer) { Binder b = Binder.of( "id", id ); if (references != null) b.set("references", serializer.serialize(references)); if (validUntil != null) b.set("valid_until", validUntil); if (data != null) b.set("data", serializer.serialize(data)); return serializer.serialize(b); }
@Override public Binder serialize(BiSerializer serializer) { Binder data = new Binder(); data.set("name", serializer.serialize(name)); data.set("nameReduced", serializer.serialize(nameReduced)); data.set("description", serializer.serialize(description)); data.set("url", serializer.serialize(url)); data.set("expiresAt", serializer.serialize(expiresAt)); data.set("entries", serializer.serialize(Do.list(entries))); return data; }
public static Binder createScriptBinder(byte[] jsFileContent, String jsFileName, JSApiScriptParameters scriptParameters, boolean putContentIntoContract) { BiSerializer biSerializer = new BiSerializer(); HashId scriptHashId = HashId.of(jsFileContent); Binder scriptBinder = new Binder(); scriptBinder.set("file_name", jsFileName); scriptBinder.set("__type", "file"); scriptBinder.set("hash_id", biSerializer.serialize(scriptHashId)); if (putContentIntoContract) scriptBinder.set("file_content", jsFileContent); scriptBinder.putAll(scriptParameters.toBinder()); return scriptBinder; }
/** * Sets number of revisions of tracking contract to hold in the storage. * @param keepRevisions is number of revisions to keep. */ public void setKeepRevisions(int keepRevisions) { if(keepRevisions < 1) throw new IllegalArgumentException("Keep revisions should be positive"); getStateData().set(KEEP_REVISIONS_FIELD_NAME, keepRevisions); this.keepRevisions = keepRevisions; updateTrackingContracts(); }
public void setBodyAsFileBinary(byte[] bodyAsBinary) { response.setBody(bodyAsBinary); response.getHeaders().set("Content-type", "application/octet-stream"); } }
public void setConditions(ScriptObjectMirror conditions) { Object paramsMap = JSApiHelpers.jo2Object(conditions); if (paramsMap instanceof HashMap) { Binder paramsBinder = new Binder(); ((HashMap)paramsMap).forEach((k, v) -> paramsBinder.set(k.toString(), v)); this.reference.setConditions(paramsBinder); } }
public JSApiChangeNumberPermission(JSApiRole role, Map<String, Object> params) { Binder paramsBinder = new Binder(); params.forEach((k, v) -> paramsBinder.set(k, v)); changeNumberPermission = new ChangeNumberPermission(role.extractRole(new JSApiAccessor()), paramsBinder); }
private Binder queryFollowerInfo(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); res.set("follower_state", null); byte[] follower_id = params.getBinary("follower_id"); byte[] followerBin = node.getLedger().getSmartContractById(HashId.withDigest(follower_id)); if (followerBin != null) { FollowerContract followerContract = (FollowerContract) Contract.fromPackedTransaction(followerBin); res.set("follower_state", followerContract.getStateData()); } return res; }
@Override public Binder serialize(BiSerializer s) { Binder binder = Binder.of( "api_level", apiLevel, "definition", definition.serializeWith(s), "state", state.serializeWith(s) ); if(transactional != null) binder.set("transactional", transactional.serializeWith(s)); return binder; }
private Binder querySlotInfo(Binder params, Session session) throws IOException { checkNode(session, true); Binder res = new Binder(); res.set("slot_state", null); byte[] slot_id = params.getBinary("slot_id"); byte[] slotBin = node.getLedger().getSmartContractById(HashId.withDigest(slot_id)); if (slotBin != null) { SlotContract slotContract = (SlotContract) Contract.fromPackedTransaction(slotBin); res.set("slot_state", slotContract.getStateData()); } return res; }
public Binder toBinder() { Binder binder = new Binder(); binder.set("compression", (isCompressed ? JSApiCompressionEnum.ZIP : JSApiCompressionEnum.RAW).toString()); binder.put("time_limit", timeLimitMillis); binder.put("permissions", permissions); binder.put("domainMasks", domainMasks); binder.put("ipMasks", ipMasks); return binder; }
/** * Saves client's javascript in contract's state. It can be executed with {@link Contract#execJS(JSApiExecOptions, byte[], String...)} */ public void setJS(byte[] jsFileContent, String jsFileName, JSApiScriptParameters scriptParameters, boolean putContentIntoContract) { String fileNameKey = JSApiHelpers.fileName2fileKey(jsFileName); Binder scriptBinder = JSApiHelpers.createScriptBinder(jsFileContent, jsFileName, scriptParameters, putContentIntoContract); Binder scripts = getData().getBinder(JSAPI_SCRIPT_FIELD, new Binder()); scripts.set(fileNameKey, scriptBinder); getData().put(JSAPI_SCRIPT_FIELD, scripts); }
/** * Saves client's javascript in contract's definition. It can be executed with {@link Contract#execJS(JSApiExecOptions, byte[], String...)} * @param putContentIntoContract pass here true to save js body in contract, in this case it's not necessary to store attached * js-files separately, needs only {@link HashId} of its. */ public void setJS(byte[] jsFileContent, String jsFileName, JSApiScriptParameters scriptParameters, boolean putContentIntoContract) { String fileNameKey = JSApiHelpers.fileName2fileKey(jsFileName); Binder scriptBinder = JSApiHelpers.createScriptBinder(jsFileContent, jsFileName, scriptParameters, putContentIntoContract); Binder scripts = getData().getBinder(JSAPI_SCRIPT_FIELD, new Binder()); scripts.set(fileNameKey, scriptBinder); getData().put(JSAPI_SCRIPT_FIELD, scripts); }
public Contract createUnsPayment() throws IOException { PrivateKey ownerKey = new PrivateKey(Do.read(rootPath + "keys/stepan_mamontov.private.unikey")); Set<PublicKey> keys = new HashSet(); keys.add(ownerKey.getPublicKey()); Contract stepaU = InnerContractsService.createFreshU(100000000, keys); Contract paymentDecreased = stepaU.createRevision(ownerKey); paymentDecreased.getStateData().set("transaction_units", stepaU.getStateData().getIntOrThrow("transaction_units") - 2000); paymentDecreased.seal(); return paymentDecreased; } }
@Test(timeout = 90000) public void checkPayment_wrongUtype() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); payment.getStateData().set("transaction_units", "33"); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@Test(timeout = 90000) public void checkPayment_minusU() throws Exception { Contract payment = checkPayment_preparePaymentContract(checkPayment_preparePrivateKeys()); payment.getStateData().set("transaction_units", -1); boolean res = payment.paymentCheck(config.getUIssuerKeys()); payment.traceErrors(); assertFalse(res); }
@Test public void transactionalData() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); String testValue = HashId.createRandom().toBase64String(); contract.getTransactionalData().set("test_value", testValue); contract.seal(); byte[] packedData = contract.getPackedTransaction(); Contract unpackedContract = Contract.fromPackedTransaction(packedData); System.out.println("unpackedContract.transactional.data.test_value: " + unpackedContract.getTransactionalData().getStringOrThrow("test_value")); assertEquals(testValue, unpackedContract.getTransactionalData().getStringOrThrow("test_value")); }