Advertisement
Guest User

Untitled

a guest
Jan 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. impl Counterparty {
  2. pub fn fingerprint(&self, contract_address: Address) -> [u8; 32] {
  3. let mut bytes: Vec<&[u8]> = Vec::new();
  4. bytes.push("Counterparty".as_bytes());
  5. bytes.push(contract_address.as_bytes());
  6.  
  7. match self {
  8. Counterparty::New { i_am_0 } => {
  9. bytes.push("New".as_bytes());
  10. bytes.push(&bool_to_bytes(*i_am_0));
  11. }
  12. Counterparty::Creating {
  13. new_channel_tx,
  14. i_am_0,
  15. } => {
  16. bytes.push("Creating".as_bytes());
  17. let n = new_channel_tx.fingerprint(contract_address);
  18. bytes.push(&n);
  19. bytes.push(&bool_to_bytes(*i_am_0));
  20. }
  21. Counterparty::OtherCreating {
  22. new_channel_tx,
  23. i_am_0,
  24. } => {
  25. bytes.push("OtherCreating".as_bytes());
  26. bytes.push(&new_channel_tx.fingerprint(contract_address));
  27. bytes.push(&bool_to_bytes(*i_am_0));
  28. }
  29. Counterparty::ReDrawing {
  30. re_draw_tx,
  31. channel,
  32. } => {
  33. bytes.push("ReDrawing".as_bytes());
  34. bytes.push(&re_draw_tx.fingerprint(contract_address));
  35. bytes.push(&channel.fingerprint(contract_address));
  36. }
  37. Counterparty::OtherReDrawing {
  38. re_draw_tx,
  39. channel,
  40. } => {
  41. bytes.push("OtherReDrawing".as_bytes());
  42. bytes.push(&re_draw_tx.fingerprint(contract_address));
  43. bytes.push(&channel.fingerprint(contract_address));
  44. }
  45. Counterparty::Open { channel } => {
  46. bytes.push(&channel.fingerprint(contract_address));
  47. }
  48. };
  49.  
  50. let fingerprint = crypto::hash_bytes(&bytes);
  51. let fingerprint: [u8; 32] = fingerprint.clone().into();
  52.  
  53. return fingerprint;
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement