Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- impl Counterparty {
- pub fn fingerprint(&self, contract_address: Address) -> [u8; 32] {
- let mut bytes: Vec<&[u8]> = Vec::new();
- bytes.push("Counterparty".as_bytes());
- bytes.push(contract_address.as_bytes());
- match self {
- Counterparty::New { i_am_0 } => {
- bytes.push("New".as_bytes());
- bytes.push(&bool_to_bytes(*i_am_0));
- }
- Counterparty::Creating {
- new_channel_tx,
- i_am_0,
- } => {
- bytes.push("Creating".as_bytes());
- let n = new_channel_tx.fingerprint(contract_address);
- bytes.push(&n);
- bytes.push(&bool_to_bytes(*i_am_0));
- }
- Counterparty::OtherCreating {
- new_channel_tx,
- i_am_0,
- } => {
- bytes.push("OtherCreating".as_bytes());
- bytes.push(&new_channel_tx.fingerprint(contract_address));
- bytes.push(&bool_to_bytes(*i_am_0));
- }
- Counterparty::ReDrawing {
- re_draw_tx,
- channel,
- } => {
- bytes.push("ReDrawing".as_bytes());
- bytes.push(&re_draw_tx.fingerprint(contract_address));
- bytes.push(&channel.fingerprint(contract_address));
- }
- Counterparty::OtherReDrawing {
- re_draw_tx,
- channel,
- } => {
- bytes.push("OtherReDrawing".as_bytes());
- bytes.push(&re_draw_tx.fingerprint(contract_address));
- bytes.push(&channel.fingerprint(contract_address));
- }
- Counterparty::Open { channel } => {
- bytes.push(&channel.fingerprint(contract_address));
- }
- };
- let fingerprint = crypto::hash_bytes(&bytes);
- let fingerprint: [u8; 32] = fingerprint.clone().into();
- return fingerprint;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement