/** * Initialize from a record and posession flag * * @param record record to get data from * @param haveCopy true if the node has a copy of the {@link Approvable} item (e.g. one can try go call {@link * com.icodici.universa.node2.network.Network#getItem(HashId, NodeInfo, Duration)} on it */ public ItemResult(StateRecord record, boolean haveCopy) { // if( record == null ) { // throw new IllegalStateException("record can not be null"); // } state = record.getState(); this.haveCopy = haveCopy; createdAt = record.getCreatedAt(); expiresAt = record.getExpiresAt(); }
@Override public String toString() { return "State<"+getId()+"/"+getRecordId()+":"+getState()+":"+getCreatedAt()+"/"+getExpiresAt()+">"; } }
statement.setBytes(1, stateRecord.getId().getDigest()); statement.setInt(2, stateRecord.getState().ordinal()); statement.setLong(3, StateRecord.unixTime(stateRecord.getCreatedAt())); statement.setLong(4, StateRecord.unixTime(stateRecord.getExpiresAt())); statement.setLong(5, stateRecord.getLockedByRecordId());
statement.setBytes(1, stateRecord.getId().getDigest()); statement.setInt(2, stateRecord.getState().ordinal()); statement.setLong(3, StateRecord.unixTime(stateRecord.getCreatedAt())); statement.setLong(4, StateRecord.unixTime(stateRecord.getExpiresAt())); statement.setLong(5, stateRecord.getLockedByRecordId());
protected void assertSameRecords(StateRecord r, StateRecord r1) { assertEquals(r.getId(), r1.getId()); assertEquals(r.getState(), r1.getState()); assertAlmostSame(r.getCreatedAt(), r1.getCreatedAt()); assertEquals(r.getRecordId(), r1.getRecordId()); assertEquals(r.getLockedByRecordId(), r1.getLockedByRecordId()); }
ledger.savePayment(parcel.getQuantasLimit()/Quantiser.quantaPerU, paymentProcessor != null ? paymentProcessor.record.getCreatedAt() : ledger.getRecord(payment.getId()).getCreatedAt()); int paidU = payload.getStateData().getInt(NSmartContract.PAID_U_FIELD_NAME, 0); if (paidU > 0) ledger.savePayment(paidU, payloadProcessor != null ? payloadProcessor.record.getCreatedAt() : ledger.getRecord(payload.getId()).getCreatedAt());
@Test public void findOrCreateAndGet() throws Exception { // Atomic new record creation HashId id = HashId.createRandom(); StateRecord r = ledger.findOrCreate(id); assertNotNull(r); assertEquals(id, r.getId()); assertEquals(ItemState.PENDING, r.getState()); assertAlmostSame(ZonedDateTime.now(), r.getCreatedAt()); // returning existing record StateRecord r1 = ledger.findOrCreate(id); assertSameRecords(r, r1); StateRecord r2 = ledger.getRecord(id); assertSameRecords(r, r2); StateRecord r3 = ledger.getRecord(HashId.createRandom()); assert (r3 == null); }
@Test public void findOrCreateAndGet() throws Exception { // Atomic new record creation HashId id = HashId.createRandom(); StateRecord r = ledger.findOrCreate(id); assertNotNull(r); assertEquals(id, r.getId()); assertEquals(ItemState.PENDING, r.getState()); assertAlmostSame(ZonedDateTime.now(), r.getCreatedAt()); // returning existing record StateRecord r1 = ledger.findOrCreate(id); assertSameRecords(r, r1); StateRecord r2 = ledger.getRecord(id); assertSameRecords(r, r2); StateRecord r3 = ledger.getRecord(HashId.createRandom()); assert (r3 == null); }
r1.setCreatedAt(r1.getCreatedAt().plusHours(1)); r1.save();