1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use base58::FromBase58;
#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct TXOutput {
pub value: i32,
pub pubkey_hash: Vec<u8>,
}
impl TXOutput {
pub fn can_be_unlocked_with(self, address: String) -> bool {
let _pubkey_hash = address.from_base58()
.unwrap()[1..21].to_vec();
return self.pubkey_hash.eq(&_pubkey_hash);
}
pub fn lock(self, _address: String) -> TXOutput {
let pubkey_hash = _address.from_base58()
.unwrap()[1..20].to_vec();
return TXOutput{
value: self.value,
pubkey_hash: pubkey_hash,
}
}
pub fn islocked_with_key(self, _pubkey_hash: Vec<u8>) -> bool {
return self.pubkey_hash.eq(&_pubkey_hash);
}
}