Skip to content

Conversation

@jrawsthorne
Copy link

This is a breaking change

pub fn put_hash_keyed<T>(&mut self, encodable: &T) -> Result<PRef, Box<dyn Error>>
where T: Serialize + BitcoinHash {
Ok(self.hammersbald.put_keyed(&encodable.bitcoin_hash()[..], serde_cbor::to_vec(encodable)?.as_slice())?)
pub fn put_hash_keyed<T>(&mut self, id: &sha256d::Hash, encodable: &T) -> Result<PRef, Box<dyn Error>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to change the API here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe T could implement an Into<Hash> here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was that the BitcoinHash trait is being removed and sha256d::Hash is hard coded for get so it makes sense that you can only insert with sha256d::Hash

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to keep the same API would be to add the BitcoinHash trait to the chaindb module and implement it on StoredHeader, which is the only type passed to push_hash_keyed. It's hard to know if any other projects are using this lib so I'm sympathetic to not changing the API too much if we don't have to.

/// Retrieve a bitcoin_object with its hash
pub fn get_hash_keyed<T>(&self, id: &sha256d::Hash) -> Result<Option<(PRef, T)>, Box<dyn Error>>
where T: DeserializeOwned + BitcoinHash{
where T: DeserializeOwned {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the BitcoinHash removed here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, this will be removed in the next version

bdb.put_hash_keyed(&genesis.bitcoin_hash().as_hash(), &genesis).unwrap();
// find it
if let Some((_, block)) = bdb.get_hash_keyed::<Block>(&genesis.bitcoin_hash()).unwrap() {
if let Some((_, block)) = bdb.get_hash_keyed::<Block>(&genesis.bitcoin_hash().as_hash()).unwrap() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use block_hash instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

block_hash is only available on master at the moment, got to wait for the next rust-bitcoin release

@jrawsthorne
Copy link
Author

It's still a bit awkward with get_hash_keyed because of the extra generic. The other way is to take a sha256d::Hash but then the caller has to call as_hash(). Probably not worth it to discuss too much as this is only really to get murmel to compile and hammersbald probably won't be used in the future

@notmandatory
Copy link

Changes look good to me. I also confirmed all tests pass:

cargo test --features="bitcoin_support"

Copy link

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NACK: BitcoinHash trait was deliberately removed from rust-bitcoin and replaced with normal txid/wtxid() and block_hash functions. I think it will be better to adopt this new API and not just to introduce deprecated trait

@notmandatory
Copy link

@jrawsthorne it sounds like your original approach at commit on the 25th with the API change and no BitcoinHash trait is the right way to go. I'll withdraw my suggestion. :-)

@jrawsthorne
Copy link
Author

Reverted to the previous state and updated the bitcoin dependency to 0.25 rather than git

Copy link

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK b753e9d

My comment on removing hex dev dependency can go into a separate PR


[dev-dependencies]
hex = "0.3"
hex = "0.4"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can get rid of this dependency like it was done for rust-bitcoin (rust-bitcoin/rust-bitcoin@07fb14b) and use Vec::from_hex instead

@stevenroose
Copy link
Collaborator

Closed in favor of #14.

@stevenroose stevenroose closed this Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants