@Override public Binder serialize(BiSerializer s) { Binder result = new Binder(); result.putAll(this); result.put("key", s.serialize(publicKey)); return result; }
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; }
public Binder serializeToBinder() { Binder data = new Binder(); data.putAll(this); data.put("key", publicKey.pack()); return data; }
private Binder answer(Binder result) { if (result == null) result = new Binder(); if (!errors.isEmpty()) { result.put("errors", errors); } return result; }
/** * Add Binder as a field with the specified index and return it in a typed manner. Sort of the syntax sugar. * * @param key * @param object * @return */ public <T extends Object> T set(String key, T object) { checkNotFrozen(); put(key, object); return (T) object; }
private Binder followerGetRate(Binder params, Session session) throws IOException { checkNode(session, true); BigDecimal rateOriginDays = config.rate.get(NSmartContract.SmartContractType.FOLLOWER1.name()); BigDecimal rateCallback = config.rate.get(NSmartContract.SmartContractType.FOLLOWER1.name() + ":callback").divide(rateOriginDays); Binder b = new Binder(); b.put("rateOriginDays", rateOriginDays.toString()); b.put("rateCallback", rateCallback.toString()); return b; }
/** * Remove all signatures from sealed binary */ public void removeAllSignatures() { if (sealedBinary == null) throw new IllegalStateException("failed to add signature: sealed binary does not exist"); Binder data = Boss.unpack(sealedBinary); List<byte[]> signatures = new ArrayList<>(); data.put("signatures", signatures); sealedByKeys.clear(); setOwnBinary(data); }
private Binder unsRate(Binder params, Session session) throws IOException { checkNode(session, true); BigDecimal rate = config.rate.get(NSmartContract.SmartContractType.UNS1.name()); String str = rate.toString(); Binder b = new Binder(); b.put("U", str); return b; }
@Override public Binder serialize(BiSerializer serializer) { Binder results = super.serialize(serializer); results.put("fields", serializer.serialize(this.fields)); return results; }
private Binder storageGetRate(Binder params, Session session) throws IOException { checkNode(session, true); BigDecimal rate = config.rate.get(NSmartContract.SmartContractType.SLOT1.name()); String str = rate.toString(); Binder b = new Binder(); b.put("U", str); return b; }
@Override public Binder serialize(BiSerializer s) { Binder b = super.serialize(s); b.put("bar", bar); return b; }
public Binder getOrCreateBinder(String key) { checkNotFrozen(); HashMap<String, Object> x = (HashMap<String, Object>) get(key); Binder b = null; if (x == null) { b = new Binder(); put(key, b); } else b = (x instanceof Binder) ? (Binder) x : new Binder(x); return b; }
static public byte[] createTargetSignature(PublicKey publicKey, byte[] data, boolean savePublicKey) { Binder targetSignatureBinder = Binder.fromKeysValues( "key", keyId(publicKey), "sha512", new Sha512().digest(data), "sha3_384", new Sha3_384().digest(data), "created_at", ZonedDateTime.now() ); if (savePublicKey) targetSignatureBinder.put("pub_key", publicKey.pack()); byte[] targetSignature = Boss.pack(targetSignatureBinder); return targetSignature; }
/** * 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); }
private void setAndCheckOldNewValues(Binder d, Binder d1, String oldValue, String newValue, String field) { assertEquals(oldValue, d.getString(field)); assertEquals(oldValue, d1.getString(field)); d1.put(field, newValue); assertEquals(oldValue, d.getString(field)); assertEquals(newValue, d1.getString(field, null)); }
@Test public void cachingNestedMaps() throws Exception { Binder a = Binder.fromKeysValues("foo", "bar"); Binder b = Binder.fromKeysValues("foo", "bar"); b.put("bar", "buzz"); Binder root = Binder.fromKeysValues("a", b, "b", b, "c", b); Binder res = Boss.unpack(Boss.pack(root)); assertEquals("buzz", res.getBinderOrThrow("c").getStringOrThrow("bar")); }