Skip to content

Commit

Permalink
Remove transaction ID to inscription ID conversion (ordinals#2370)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Aug 25, 2023
1 parent d58956c commit f0382b2
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 58 deletions.
78 changes: 51 additions & 27 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ mod tests {
let context = Context::builder().build();
context.mine_blocks(1);
let txid = context.rpc_server.broadcast_tx(template.clone());
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };
context.mine_blocks(1);

assert_eq!(
Expand All @@ -1324,7 +1324,7 @@ mod tests {
.build();
context.mine_blocks(1);
let txid = context.rpc_server.broadcast_tx(template);
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };
context.mine_blocks(1);

assert_eq!(
Expand Down Expand Up @@ -1639,7 +1639,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down Expand Up @@ -1673,7 +1673,7 @@ mod tests {
..Default::default()
});

let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down Expand Up @@ -1702,7 +1702,7 @@ mod tests {
..Default::default()
});

let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand All @@ -1727,7 +1727,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down Expand Up @@ -1772,14 +1772,20 @@ mod tests {
..Default::default()
});

let first_inscription_id = InscriptionId::from(first_txid);
let first_inscription_id = InscriptionId {
txid: first_txid,
index: 0,
};

let second_txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(2, 0, 0)],
witness: inscription("text/png", [1; 100]).to_witness(),
..Default::default()
});
let second_inscription_id = InscriptionId::from(second_txid);
let second_inscription_id = InscriptionId {
txid: second_txid,
index: 0,
};

context.mine_blocks(1);

Expand Down Expand Up @@ -1826,7 +1832,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down Expand Up @@ -1875,7 +1881,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down Expand Up @@ -1919,7 +1925,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down Expand Up @@ -1955,7 +1961,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down Expand Up @@ -1992,7 +1998,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

let coinbase_tx = context.mine_blocks(1)[0].txdata[0].txid();

Expand Down Expand Up @@ -2021,7 +2027,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks_with_subsidy(1, 0);

Expand All @@ -2047,7 +2053,10 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let first_inscription_id = InscriptionId::from(first_txid);
let first_inscription_id = InscriptionId {
txid: first_txid,
index: 0,
};

context.mine_blocks_with_subsidy(1, 0);
context.mine_blocks(1);
Expand All @@ -2058,7 +2067,10 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let second_inscription_id = InscriptionId::from(second_txid);
let second_inscription_id = InscriptionId {
txid: second_txid,
index: 0,
};

context.mine_blocks_with_subsidy(1, 0);

Expand Down Expand Up @@ -2172,7 +2184,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };
context.mine_blocks(1);

context.rpc_server.broadcast_tx(TransactionTemplate {
Expand Down Expand Up @@ -2205,7 +2217,7 @@ mod tests {
output_values: &[0, 50 * COIN_VALUE],
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };
context.mine_blocks(1);

context.index.assert_inscription_location(
Expand All @@ -2230,7 +2242,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };
context.mine_blocks_with_subsidy(1, 0);

context.index.assert_inscription_location(
Expand Down Expand Up @@ -2340,7 +2352,7 @@ mod tests {
..Default::default()
});

let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

assert_eq!(
context
Expand Down Expand Up @@ -2401,7 +2413,10 @@ mod tests {

context.mine_blocks(1);

let inscription_id = InscriptionId::from(first);
let inscription_id = InscriptionId {
txid: first,
index: 0,
};

assert_eq!(
context
Expand Down Expand Up @@ -2432,7 +2447,10 @@ mod tests {
..Default::default()
});

let inscription_id = InscriptionId::from(second);
let inscription_id = InscriptionId {
txid: second,
index: 0,
};

context.mine_blocks(1);

Expand All @@ -2450,13 +2468,19 @@ mod tests {

assert!(context
.index
.get_inscription_entry(second.into())
.get_inscription_by_id(InscriptionId {
txid: second,
index: 0
})
.unwrap()
.is_some());

assert!(context
.index
.get_inscription_by_id(second.into())
.get_inscription_by_id(InscriptionId {
txid: second,
index: 0
})
.unwrap()
.is_some());
}
Expand All @@ -2472,7 +2496,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand All @@ -2499,7 +2523,7 @@ mod tests {
witness: inscription("text/plain", "hello").to_witness(),
..Default::default()
});
ids.push(InscriptionId::from(txid));
ids.push(InscriptionId { txid, index: 0 });
context.mine_blocks(1);
}

Expand Down Expand Up @@ -2572,7 +2596,7 @@ mod tests {
..Default::default()
});

let inscription_id = InscriptionId::from(txid);
let inscription_id = InscriptionId { txid, index: 0 };

context.mine_blocks(1);

Expand Down
6 changes: 0 additions & 6 deletions src/inscription_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ impl FromStr for InscriptionId {
}
}

impl From<Txid> for InscriptionId {
fn from(txid: Txid) -> Self {
Self { txid, index: 0 }
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
Loading

0 comments on commit f0382b2

Please sign in to comment.