Skip to content
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

Get confirmed + unconfirmed unspent boxes EP #246

Merged
merged 6 commits into from
Dec 19, 2022

Conversation

semyonoskin
Copy link
Collaborator

val ergoTree = addressToErgoTreeHex(address)
(for {
nConfirmed <- outputs.countUnspentByErgoTree(ergoTree)
nUnonfirmed <- uoutputs.sumUnspentByErgoTree(ergoTree)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
nUnonfirmed <- uoutputs.sumUnspentByErgoTree(ergoTree)
nUnсonfirmed <- uoutputs.sumUnspentByErgoTree(ergoTree)

val ergoTree = addressToErgoTreeHex(address)
(for {
nConfirmed <- outputs.countUnspentByErgoTree(ergoTree)
nUnonfirmed <- uoutputs.sumUnspentByErgoTree(ergoTree)
Copy link
Member

Choose a reason for hiding this comment

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

Please look careful at what sumUnspentByErgoTree really does

|select coalesce(cast(sum(o.value) as bigint), 0) from node_u_outputs o

Comment on lines 399 to 409
confirmed <- outputs
.streamUnspentByErgoTree(ergoTree, paging.offset, paging.limit, ord.value)
.chunkN(serviceSettings.chunkSize)
.through(toOutputInfo)
.map(UOutputInfo.fromOutputInfo)
.to[List]
unconfirmed <- Stream
.evalSeq(
uoutputs
.getAllUnspentByErgoTree(ergoTree)
)
Copy link
Member

Choose a reason for hiding this comment

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

So it seems your paging doesn't work as it should here. You retrieve a slice of expected number of confirmed outputs streamUnspentByErgoTree(ergoTree, paging.offset, paging.limit, ord.value) and then concatenate it with unknown number of unconfirmed outputs.

Comment on lines 191 to 211
val q = sql"""
|select * from (
|select distinct on (o.box_id)
| o.box_id,
| o.tx_id,
| o.value,
| o.creation_height,
| o.index,
| o.ergo_tree,
| o.ergo_tree_template_hash,
| o.address,
| o.additional_registers,
| null
|from node_u_outputs o
|left join node_u_inputs i on i.box_id = o.box_id
|where i.box_id is null and o.ergo_tree = $ergoTree
|union all
|select distinct on (o.box_id, o.global_index)
| o.box_id,
| o.tx_id,
| o.value,
Copy link
Member

Choose a reason for hiding this comment

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

Please indent SQL

.in(PathPrefix / "unspent" / "all" / "byAddress" / path[Address])
.in(paging(settings.maxEntitiesPerRequest))
.in(ordering)
.out(jsonBody[Items[UOutputInfo]])
Copy link
Member

Choose a reason for hiding this comment

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

Let's not shrink OutputInfo down to UOutputInfo (omitting some fields). I'd suggest adding new coproduct that contains both variants (AnyOutputInfo = OutputInfo | UOutputInfo).

@semyonoskin semyonoskin requested a review from oskin1 November 21, 2022 11:32
@oskin1 oskin1 merged commit cbd915f into master Dec 19, 2022
@oskin1 oskin1 deleted the dev-353-api-method-to-retrieve branch December 19, 2022 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants