parent
dba6d7a8a6
commit
2379792e0a
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "silk"
|
||||
description = "A silky smooth implementation of the Loom architecture"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
documentation = "https://docs.rs/silk"
|
||||
homepage = "http://loomprotocol.com/"
|
||||
repository = "https://github.com/loomprotocol/silk"
|
||||
|
@ -53,3 +53,4 @@ serde_json = "1.0.10"
|
|||
ring = "0.12.1"
|
||||
untrusted = "0.5.1"
|
||||
bincode = "1.0.0"
|
||||
chrono = { version = "0.4.0", features = ["serde"] }
|
||||
|
|
|
@ -12,6 +12,7 @@ use historian::{reserve_signature, Historian};
|
|||
use std::sync::mpsc::SendError;
|
||||
use std::collections::HashMap;
|
||||
use std::result;
|
||||
use chrono::prelude::*;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum AccountingError {
|
||||
|
@ -138,6 +139,18 @@ impl Accountant {
|
|||
self.process_transaction(tr).map(|_| sig)
|
||||
}
|
||||
|
||||
pub fn transfer_on_date(
|
||||
self: &mut Self,
|
||||
n: i64,
|
||||
keypair: &KeyPair,
|
||||
to: PublicKey,
|
||||
dt: DateTime<Utc>,
|
||||
) -> Result<Signature> {
|
||||
let tr = Transaction::new_on_date(keypair, to, dt, n, self.last_id);
|
||||
let sig = tr.sig;
|
||||
self.process_transaction(tr).map(|_| sig)
|
||||
}
|
||||
|
||||
pub fn get_balance(self: &Self, pubkey: &PublicKey) -> Option<i64> {
|
||||
self.balances.get(pubkey).map(|x| *x)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ pub mod accountant;
|
|||
pub mod accountant_skel;
|
||||
pub mod accountant_stub;
|
||||
extern crate bincode;
|
||||
extern crate chrono;
|
||||
extern crate generic_array;
|
||||
extern crate rayon;
|
||||
extern crate ring;
|
||||
|
|
|
@ -4,11 +4,20 @@ use signature::{KeyPair, KeyPairUtil, PublicKey, Signature, SignatureUtil};
|
|||
use serde::Serialize;
|
||||
use bincode::serialize;
|
||||
use hash::Hash;
|
||||
use chrono::prelude::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub enum Condition {
|
||||
DateTime(DateTime<Utc>),
|
||||
Cancel,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub struct Transaction<T> {
|
||||
pub from: PublicKey,
|
||||
pub to: PublicKey,
|
||||
pub if_all: Vec<Condition>,
|
||||
pub unless_any: Vec<Condition>,
|
||||
pub asset: T,
|
||||
pub last_id: Hash,
|
||||
pub sig: Signature,
|
||||
|
@ -19,6 +28,28 @@ impl<T: Serialize> Transaction<T> {
|
|||
let mut tr = Transaction {
|
||||
from: from_keypair.pubkey(),
|
||||
to,
|
||||
if_all: vec![],
|
||||
unless_any: vec![],
|
||||
asset,
|
||||
last_id,
|
||||
sig: Signature::default(),
|
||||
};
|
||||
tr.sign(from_keypair);
|
||||
tr
|
||||
}
|
||||
|
||||
pub fn new_on_date(
|
||||
from_keypair: &KeyPair,
|
||||
to: PublicKey,
|
||||
dt: DateTime<Utc>,
|
||||
asset: T,
|
||||
last_id: Hash,
|
||||
) -> Self {
|
||||
let mut tr = Transaction {
|
||||
from: from_keypair.pubkey(),
|
||||
to,
|
||||
if_all: vec![Condition::DateTime(dt)],
|
||||
unless_any: vec![Condition::Cancel],
|
||||
asset,
|
||||
last_id,
|
||||
sig: Signature::default(),
|
||||
|
@ -72,6 +103,8 @@ mod tests {
|
|||
let claim0 = Transaction {
|
||||
from: Default::default(),
|
||||
to: Default::default(),
|
||||
if_all: Default::default(),
|
||||
unless_any: Default::default(),
|
||||
asset: 0u8,
|
||||
last_id: Default::default(),
|
||||
sig: Default::default(),
|
||||
|
|
Loading…
Reference in New Issue