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