| 31 | } |
| 32 | |
| 33 | pub fn transfer_to(&mut self, to: &mut Self, amount: u64, fee: u64) |
| 34 | -> Result<Transaction, String> |
| 35 | { |
| 36 | if amount + fee > self.balance { |
| 37 | return Err("Error: not enough amount!".to_string()); |
| 38 | } |
| 39 | |
| 40 | self.balance -= amount; |
| 41 | self.balance -= fee; |
| 42 | self.nonce += 1; |
| 43 | self.set_hash(); |
| 44 | |
| 45 | to.balance += amount; |
| 46 | to.nonce += 1; |
| 47 | to.set_hash(); |
| 48 | |
| 49 | let sign = format!("{} -> {}: {} btc", |
| 50 | self.address.clone(), |
| 51 | to.address.clone(), |
| 52 | amount); |
| 53 | let tx = Transaction::new(self.address.clone(), |
| 54 | to.address.clone(), |
| 55 | amount, fee, self.nonce, sign); |
| 56 | Ok(tx) |
| 57 | } |
| 58 | |
| 59 | pub fn account_info(&self) { |
| 60 | println!("{:#?}", &self); |