-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chaincash store updates/impl #43
Draft
ross-weir
wants to merge
20
commits into
master
Choose a base branch
from
start-datastore-impl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d29cdba
chaincash store updates
ross-weir 3d3189f
remove unneeded trait bounds
ross-weir ca1e32e
more store crate work
ross-weir d2f2c15
init entities crate
ross-weir 83e4939
update root deps
ross-weir 01cc726
more work
ross-weir 73d33ab
more work
ross-weir b3a5136
remove unneeded namespace
ross-weir f740763
try from for ref instead
ross-weir a5eee61
more updates
ross-weir 22d7f4c
cargo update deps
ross-weir 246d25a
refactory store services, small tidy
ross-weir 1c4d3a4
pass ergo box directly to repo
ross-weir e56056a
fix return types
ross-weir fa5e73c
more small stuff
ross-weir a877773
work
ross-weir 2f082dd
more work, everything building again
ross-weir 7058006
update node lib, clean errors
ross-weir c38f10a
small tidy
ross-weir 60e7f5c
add denomination to reserves with placeholder
ross-weir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use ergo_lib::{ | ||
ergo_chain_types::EcPoint, | ||
ergotree_ir::{ | ||
chain::ergo_box::{ErgoBox, NonMandatoryRegisterId, RegisterValueError}, | ||
mir::constant::TryExtractInto, | ||
types::stype::SType, | ||
}, | ||
}; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum Error { | ||
#[error("Failed to access register")] | ||
BadRegister(#[from] RegisterValueError), | ||
|
||
#[error("Box field was unexpectedly empty: {0}")] | ||
FieldNotSet(&'static str), | ||
|
||
#[error("Box field '{field}' was set to incorrect type: {tpe}")] | ||
InvalidType { field: String, tpe: SType }, | ||
} | ||
|
||
pub struct ReserveBoxSpec { | ||
pub owner: EcPoint, | ||
pub refund_height: i64, | ||
pub identifier: String, | ||
} | ||
|
||
impl TryFrom<&ErgoBox> for ReserveBoxSpec { | ||
type Error = Error; | ||
|
||
fn try_from(value: &ErgoBox) -> Result<Self, Self::Error> { | ||
let owner = value | ||
.get_register(NonMandatoryRegisterId::R4.into())? | ||
.ok_or_else(|| Error::FieldNotSet("owner")) | ||
.and_then(|reg| { | ||
if reg.tpe == SType::SGroupElement { | ||
Ok(reg.v.try_extract_into::<EcPoint>().unwrap()) | ||
} else { | ||
Err(Error::InvalidType { | ||
field: "owner".to_owned(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this field could be |
||
tpe: reg.tpe, | ||
}) | ||
} | ||
})?; | ||
let refund_height = value | ||
.get_register(NonMandatoryRegisterId::R5.into())? | ||
.ok_or_else(|| Error::FieldNotSet("refund_height")) | ||
.and_then(|reg| { | ||
if reg.tpe == SType::SLong { | ||
Ok(reg.v.try_extract_into::<i64>().unwrap()) | ||
} else { | ||
Err(Error::InvalidType { | ||
field: "refund_height".to_owned(), | ||
tpe: reg.tpe, | ||
}) | ||
} | ||
})?; | ||
let identifier = value | ||
.tokens | ||
.as_ref() | ||
.ok_or_else(|| Error::FieldNotSet("reserve box missing NFT"))? | ||
.get(0) | ||
.ok_or_else(|| Error::FieldNotSet("token at index 0 missing, no identifier nft"))? | ||
.token_id; | ||
|
||
Ok(Self { | ||
owner, | ||
refund_height, | ||
identifier: String::from(identifier), | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,6 @@ | ||
pub mod boxes; | ||
pub mod contracts; | ||
pub mod node; | ||
pub mod transactions; | ||
|
||
use thiserror::Error; | ||
|
||
pub use ergo_client::Error as ClientError; | ||
pub use transactions::TransactionService; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum Error { | ||
#[error("Ergo client error: {0}")] | ||
Client(#[from] ergo_client::Error), | ||
|
||
#[error("Ergo Node client error")] | ||
Node(#[from] ergo_client::node::NodeError), | ||
|
||
#[error("transaction error: {0}")] | ||
Transaction(#[from] transactions::TransactionError), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "chaincash_services" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
|
||
[dependencies] | ||
bs58 = "0.5.0" | ||
ergo_lib = { workspace = true } | ||
ergo_client = { workspace = true } | ||
chaincash_store = { path = "../chaincash_store" } | ||
chaincash_offchain = { path = "../chaincash_offchain" } | ||
thiserror = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod transaction; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should also check the ergo tree to ensure its a reserve box