Use Transfer struct on the client side too
Sharing is caring.
This commit is contained in:
parent
e701ccc949
commit
282afee47e
|
@ -1,6 +1,6 @@
|
||||||
use std::io;
|
use std::io;
|
||||||
use accountant::Accountant;
|
use accountant::Accountant;
|
||||||
use event::{Event, PublicKey, Signature, Transfer};
|
use event::{Event, PublicKey, Transfer};
|
||||||
use log::{Entry, Sha256Hash};
|
use log::{Entry, Sha256Hash};
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
|
@ -11,22 +11,10 @@ pub struct AccountantSkel {
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum Request {
|
pub enum Request {
|
||||||
Transaction {
|
Transaction(Transfer<i64>),
|
||||||
from: PublicKey,
|
GetBalance { key: PublicKey },
|
||||||
to: PublicKey,
|
GetEntries { last_id: Sha256Hash },
|
||||||
val: i64,
|
GetId { is_last: bool },
|
||||||
last_id: Sha256Hash,
|
|
||||||
sig: Signature,
|
|
||||||
},
|
|
||||||
GetBalance {
|
|
||||||
key: PublicKey,
|
|
||||||
},
|
|
||||||
GetEntries {
|
|
||||||
last_id: Sha256Hash,
|
|
||||||
},
|
|
||||||
GetId {
|
|
||||||
is_last: bool,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
@ -43,20 +31,8 @@ impl AccountantSkel {
|
||||||
|
|
||||||
pub fn process_request(self: &mut Self, msg: Request) -> Option<Response> {
|
pub fn process_request(self: &mut Self, msg: Request) -> Option<Response> {
|
||||||
match msg {
|
match msg {
|
||||||
Request::Transaction {
|
Request::Transaction(transfer) => {
|
||||||
from,
|
let event = Event::Transaction(transfer);
|
||||||
to,
|
|
||||||
val,
|
|
||||||
last_id,
|
|
||||||
sig,
|
|
||||||
} => {
|
|
||||||
let event = Event::Transaction(Transfer {
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
data: val,
|
|
||||||
last_id,
|
|
||||||
sig,
|
|
||||||
});
|
|
||||||
if let Err(err) = self.acc.process_event(event) {
|
if let Err(err) = self.acc.process_event(event) {
|
||||||
eprintln!("Transfer error: {:?}", err);
|
eprintln!("Transfer error: {:?}", err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use std::io;
|
use std::io;
|
||||||
use bincode::{deserialize, serialize};
|
use bincode::{deserialize, serialize};
|
||||||
use event::{get_pubkey, get_signature, sign_transaction_data, PublicKey, Signature};
|
use event::{get_pubkey, get_signature, sign_transaction_data, PublicKey, Signature, Transfer};
|
||||||
use log::{Entry, Sha256Hash};
|
use log::{Entry, Sha256Hash};
|
||||||
use ring::signature::Ed25519KeyPair;
|
use ring::signature::Ed25519KeyPair;
|
||||||
use accountant_skel::{Request, Response};
|
use accountant_skel::{Request, Response};
|
||||||
|
@ -33,13 +33,13 @@ impl AccountantStub {
|
||||||
last_id: Sha256Hash,
|
last_id: Sha256Hash,
|
||||||
sig: Signature,
|
sig: Signature,
|
||||||
) -> io::Result<usize> {
|
) -> io::Result<usize> {
|
||||||
let req = Request::Transaction {
|
let req = Request::Transaction(Transfer {
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
val,
|
data: val,
|
||||||
last_id,
|
last_id,
|
||||||
sig,
|
sig,
|
||||||
};
|
});
|
||||||
let data = serialize(&req).unwrap();
|
let data = serialize(&req).unwrap();
|
||||||
self.socket.send_to(&data, &self.addr)
|
self.socket.send_to(&data, &self.addr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue