Skip to content

add proof-of-work for token acquisition#77

Draft
FlorianUekermann wants to merge 1 commit intov0from
pow
Draft

add proof-of-work for token acquisition#77
FlorianUekermann wants to merge 1 commit intov0from
pow

Conversation

@FlorianUekermann
Copy link
Contributor

untested draft for API decisions

let res = self.send_http(request).await?;
let res = parse_response::<AcquireToken2Output>(res).await?;
let mut pow = None;
let res = loop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Needs to terminate.

#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct AcquireToken {
pub account_id: AccountId,
pub pow: Option<PowOutput>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Expand this or at least add a doc comment.

})) = &res
&& pow.is_none()
{
pow = Some(pow_input.solve(&account_id));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the hard part of this is that we should be giving client feedback. But we can add that later. There are basically two cases:

  1. We return trivial PoW challenges, deterring lazy people. UI change is not necessary.
  2. We return difficult challenges, hopefully adding notable cost. UI change seems pretty important.


#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct PowInput {
pub nonce: u128,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

decided to use string

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PowOutput {
pub nonce: u128,
pub solutions: Vec<u128>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

decided to use strings

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.

2 participants