/** * Update recordId. Normally, only {@link Ledger} do it, so avoid calling it. The recordId could be set only if it * is not yet set and there is a connected ledger. * * @param recordId id of record as long */ public void setRecordId(long recordId) { checkLedgerExists(); if (this.recordId != 0 && this.recordId != recordId) throw new IllegalStateException("can't change already assigned recordId"); this.recordId = recordId; }
public StateRecord reload() throws NotFoundException { checkLedgerExists(); if (recordId == 0) throw new IllegalStateException("can't reload record without recordId (new?)"); ledger.reload(this); return this; }
public void destroy() { checkLedgerExists(); ledger.destroy(this); }
/** * Set record to the approved state and saves it. Note that this process does not resolve any dependencies as for * now and does not revoke any records locked for revocation. This could be changed though. */ public void approve() { checkLedgerExists(); // check sanity if (state.isPending()) { setState(ItemState.APPROVED); save(); } else throw new IllegalStateException("attempt to approve record that is not pending: " + state); }
/** * 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; }
checkLedgerExists(); if (state != ItemState.PENDING) throw new IllegalStateException("only pending records are allowed to lock others");