/** * Create a record, locked for approval, e.g. item that will be creared (and approved) by current item if it will * get the positive consensus. Throws {@link IllegalStateException} if this record is not in a proper state to * perform this operation, e.g. not is in {@link ItemState#PENDING} - what means, the local check is not yet * finished. * <p> * Note that items that are already locally checked ({@link ItemState#PENDING_NEGATIVE} or {@link * ItemState#PENDING_POSITIVE} can not create any output locks. * * @param id id of the new item to be locked for approval * @return the record of the new item locked for creatoin pn success, null it such item already exists and not * locked for apporoval by us. */ public StateRecord createOutputLockRecord(HashId id) { checkLedgerExists(); checkHaveRecordId(); if (state != ItemState.PENDING) throw new IllegalStateException("wrong state to createOutputLockRecord: " + state); StateRecord newRecord = ledger.getRecord(id); if (newRecord != null) { // if it is not locked for approval - failure if (newRecord.state != ItemState.LOCKED_FOR_CREATION) return null; // it it is locked by us, ok return newRecord.lockedByRecordId == recordId ? newRecord : null; } newRecord = ledger.createOutputLockRecord(recordId, id); return newRecord; }