public String getOrigin() { return this.currentContract.getOrigin().toBase64String(); }
/** * Gets complex "id" of current revision * @return revision "id" in format ORIGIN/PARENT/REVISION/BRANCH */ public String getRevisionId() { String parentId = getParent() == null ? "" : (getParent().toBase64String() + "/"); StringBuilder sb = new StringBuilder(getOrigin().toBase64String() + "/" + parentId + state.revision); if (state.branchId != null) sb.append("/" + state.branchId.toString()); return sb.toString(); }
public JSApiOriginStorage getOriginStorage() { if (scriptParameters.checkPermission(JSApiScriptParameters.ScriptPermissions.PERM_ORIGIN_STORAGE)) return new JSApiOriginStorage(this.currentContract.getOrigin()); throw new IllegalArgumentException("access denied: missing permission " + JSApiScriptParameters.ScriptPermissions.PERM_ORIGIN_STORAGE.toString()); }
/** * Modifies payment contract by making ready for escrow. * To payment contract is added {@link Contract.Transactional} section with 2 references: send_payment_to_executor, return_payment_to_customer. * The owner of payment contract is set to {@link ListRole} contains customer role with return_payment_to_customer reference * and executor role with send_payment_to_executor reference. Any of these roles is sufficient to own a payment contract. * * @param escrow is internal escrow contract to use with payment. Must be returned from {@link ContractsService#createInternalEscrowContract(Collection, Collection, Collection, Collection)} * @param payment contract to update. Must not be registered (new root or new revision) * @param paymentOwnerKeys are keys required for use payment contract (usually, owner private keys). May be null, if payment will be signed later * @param customerKeys are customer public keys of escrow contract * @param executorKeys are executor public keys of escrow contract * * @return payment contract ready for escrow */ public static Contract modifyPaymentForEscrowContract( Contract escrow, Contract payment, Collection<PrivateKey> paymentOwnerKeys, Collection<PublicKey> customerKeys, Collection<PublicKey> executorKeys) { return modifyPaymentForEscrowContract(escrow.getOrigin().toBase64String(), payment, paymentOwnerKeys, customerKeys, executorKeys); }
result = (origin == null || !(contract.getOrigin().equals(origin)));
@Override public void putKeepingItem(StateRecord record, Approvable item) { if (item instanceof Contract) { try (PooledDb db = dbPool.db()) { try ( PreparedStatement statement = db.statement( "insert into keeping_items (id,hash,origin,packed) values(?,?,?,?);" ) ) { if (record != null) statement.setLong(1, record.getRecordId()); else statement.setNull(1, Types.INTEGER); statement.setBytes(2, ((Contract) item).getId().getDigest()); statement.setBytes(3, ((Contract) item).getOrigin().getDigest()); statement.setBytes(4, ((Contract) item).getPackedTransaction()); db.updateWithStatement(statement); } catch (Exception e) { e.printStackTrace(); throw e; } } catch (SQLException se) { se.printStackTrace(); throw new Failure("keeping item save failed:" + se); } catch (Exception e) { e.printStackTrace(); } } }
public void checkAllContracts() { //final AtomicBoolean needToReload = new AtomicBoolean(false); endpoints.forEach((endpoint, env) -> { HashId slotId = env.getSlotId(); HashId originId = env.getCurrentContract().getOrigin(); byte[] contractBinFromSlot1 = slot1Requestor.queryContract(slotId, originId); if (contractBinFromSlot1 != null) { try { Contract contractFromSlot1 = Contract.fromPackedTransaction(contractBinFromSlot1); if (contractFromSlot1.getRevision() > env.getCurrentContract().getRevision()) { System.err.println("JSApiHttpServer warning: contract origin="+originId+" changed in slot1, endpoint: " + endpoint); env.updateThisEnvironmentByName(contractFromSlot1, execOptions); } } catch (IOException e) { System.err.println("JSApiHttpServer error: unable to unpack latest contract origin=" + originId + " from slot1, update it, endpoint: " + endpoint + ", err: " + e); } catch (Exception e) { System.err.println("JSApiHttpServer error while update JSApiEnvironment: " + e); e.printStackTrace(); } } HashId id = env.getCurrentContract().getId(); if (!contractChecker.isApproved(id)) { System.err.println("JSApiHttpServer warning: contract id="+id+" is not approved, disabled " + endpoint); endpoints.remove(endpoint); } }); }
if(parent != null) { contract.getState().setParent(parent.getId()); contract.getState().setOrigin(parent.getOrigin()); contract.getState().setRevision(parent.getRevision()+1); contract.getDefinition().setExpiresAt(parent.getDefinition().getExpiresAt());
if (!rm.origin.equals(refContract.getOrigin())) { res = false; addError(Errors.BAD_REF, "origin mismatch");
/** * Completes escrow contract. All linked payments are made available to the executor. * For registration completed escrow contract require quorum of 2 of 3 roles: customer, executor and arbitrator. * * @param escrow contract (external or internal) to complete. Must be registered for creation new revision * * @return completed internal escrow contract or null if error occurred */ public static Contract completeEscrowContract(Contract escrow) { Contract escrowInside = escrow; if (!escrow.getStateData().getString("status", "null").equals("opened")) { // external escrow contract (escrow pack) // Find internal escrow contract in external escrow contract (escrow pack) String escrowOrigin = escrow.getDefinition().getData().getString("EscrowOrigin", null); if (escrowOrigin == null) return null; escrowInside = null; for (Contract c : escrow.getNew()) if (c.getOrigin().toBase64String().equals(escrowOrigin) && c.getStateData().getString("status", "null").equals("opened")) escrowInside = c; if (escrowInside == null) return null; } Contract revisionEscrow = escrowInside.createRevision(); revisionEscrow.getStateData().set("status", "completed"); revisionEscrow.seal(); return revisionEscrow; }
/** * Cancels escrow contract. All linked payments are made available to the customer. * For registration canceled escrow contract require quorum of 2 of 3 roles: customer, executor and arbitrator. * * @param escrow contract (external or internal) to cancel. Must be registered for creation new revision * * @return canceled internal escrow contract or null if error occurred */ public static Contract cancelEscrowContract(Contract escrow) { Contract escrowInside = escrow; if (!escrow.getStateData().getString("status", "null").equals("opened")) { // external escrow contract (escrow pack) // Find internal escrow contract in external escrow contract (escrow pack) String escrowOrigin = escrow.getDefinition().getData().getString("EscrowOrigin", null); if (escrowOrigin == null) return null; escrowInside = null; for (Contract c : escrow.getNew()) if (c.getOrigin().toBase64String().equals(escrowOrigin) && c.getStateData().getString("status", "null").equals("opened")) escrowInside = c; if (escrowInside == null) return null; } Contract revisionEscrow = escrowInside.createRevision(); revisionEscrow.getStateData().set("status", "canceled"); revisionEscrow.seal(); return revisionEscrow; }
if (c.getOrigin().toBase64String().equals(escrowOrigin) && c.getStateData().getString("status", "null").equals("opened")) escrowCheck = true;
System.out.println("true money origin: " + c1.getOrigin().toBase64String()); Contract c1copy = new Contract(c1.getLastSealedBinary()); System.out.println("money after split (c1): " + c1.getStateData().getIntOrThrow("amount")); System.out.println("money after split (c2): " + c2.getStateData().getIntOrThrow("amount")); System.out.println("check after split (c1.origin): " + c1.getOrigin().toBase64String()); System.out.println("check after split (c2.origin): " + c2.getOrigin().toBase64String()); ((Contract)c1.getRevokingItems().iterator().next()).getStateData().set("amount", 2000); c1.addSignerKey(key); System.out.println("check after snatch (c1.origin): " + c1.getOrigin().toBase64String()); System.out.println("check after snatch (c2.origin): " + c2.getOrigin().toBase64String()); System.out.println("check after snatch (c1copy.origin): " + c1copy.getOrigin().toBase64String()); registerAndCheckDeclined(c2);
contract.getState().setJS(js.getBytes(), "client script.js", scriptParameters); contract.seal(); Paths.get(originStoragePath + JSApiHelpers.hashId2hex(contract.getOrigin()) + "/" + testFileName).toFile().delete(); ScriptObjectMirror res = (ScriptObjectMirror)contract.execJS(new JSApiExecOptions(), js.getBytes()); assertEquals(testString1, res.get("0"));
((FollowerContract)smartContract).putTrackingOrigin(simpleContract.getOrigin(), "http://localhost:7777/follow.callback", callbackKey); assertEquals(((FollowerContract) smartContract).getTrackingOrigins().get(simpleContract.getOrigin()), "http://localhost:7777/follow.callback"); assertTrue(((FollowerContract) smartContract).isOriginTracking(simpleContract.getOrigin())); assertTrue(((FollowerContract) smartContract).isCallbackURLUsed("http://localhost:7777/follow.callback"));
@Override public Set<HashId> saveEnvironment(NImmutableEnvironment environment) { Set<HashId> conflicts = saveEnvironment_getConflicts(environment); if (conflicts.size() == 0) { NSmartContract nsc = environment.getContract(); removeEnvironment(nsc.getId()); long envId = saveEnvironmentToStorage(nsc.getExtendedType(), nsc.getId(), Boss.pack(environment.getMutable().getKVStore()), nsc.getPackedTransaction()); for (NameRecord nr : environment.nameRecords()) { NNameRecord nnr = (NNameRecord)nr; nnr.setEnvironmentId(envId); addNameRecord(nnr); } for (ContractSubscription css : environment.subscriptions()) saveSubscriptionInStorage(css.getHashId(), css.isChainSubscription(), css.expiresAt(), envId); for (ContractStorage cst : environment.storages()) saveContractInStorage(cst.getContract().getId(), cst.getPackedContract(), cst.expiresAt(), cst.getContract().getOrigin(), envId); FollowerService fs = environment.getFollowerService(); if (fs != null) saveFollowerEnvironment(envId, fs.expiresAt(), fs.mutedAt(), fs.getCallbacksSpent(), fs.getStartedCallbacks()); } return conflicts; }
escrowPack.getDefinition().getData().set("EscrowOrigin", internalEscrow.getOrigin().toBase64String());
assertEquals(uns.getUnsName(reducedName).getUnsURL(), "http://test_modified.com"); assertNotEquals(uns.getUnsName(reducedName).findUnsRecordByOrigin(referencesContract.getOrigin()), -1); assertNotEquals(uns.getUnsName(reducedName).findUnsRecordByKey(randomPrivKey.getPublicKey()), -1); assertNotEquals(uns.getUnsName(reducedName).findUnsRecordByAddress(new KeyAddress(randomPrivKey.getPublicKey(), 0, true)), -1);