Skip to content

Conversation

@itswisdomagain
Copy link

@itswisdomagain itswisdomagain commented Aug 7, 2019

Ticket purchase feature without user signup/login can be accessed by making a POST request to api/{version}/purchaseticket where version can be v1 or v2, passing UserPubKeyAddr in post body.

A pubkeyaddr can be generated by executing the following dcrctl commands against dcrwallet.
First, create a new wallet address with getnewaddress. Then, call validateaddress and retrieve the address listed in the pubkeyaddr field of the response. The pubkeyaddr starts with Tk.

The following is an example:

$ dcrctl --testnet --wallet getnewaddress
TsExampleAddr1For2Demo3PurposesOnly
$ dcrctl --testnet --wallet validateaddress TsExampleAddr1For2Demo3PurposesOnly
{
  "isvalid": true,
  "address": "TsExampleAddr1For2Demo3PurposesOnly",
  "ismine": true,
  "pubkeyaddr": "TkExample0Addr1For2Demo4Purposes5Only6Do7Not8Use9Pls0",
  "pubkey": "022801337beefc0ffee1dab8d4ffa898a782466c9a1fc00ca8863de5438dc07dcc",
  "iscompressed": true,
  "account": "default"
}

Calling the new endpoint with a valid pubkeyaddr returns the following (sample) data:

{
    "status": "success",
    "code": 0,
    "message": "APIPurchaseTicket: purchaseinfo retrieved for existing userPubKeyAddr",
    "data": {
        "PoolAddress": "TsoWCv4btvs2276yZ9qQkNL1xv5EbrBLjAJ",
        "PoolFees": 7.5,
        "Script": "512102ffbb68c445608d24239c4f1435cea18a00a652d5296481123bbc40546f01415521038d980deefd1d7bee8e195204b2e00f87904ca992bf7995bca56e928c8fefc8b552ae",
        "TicketAddress": "TcZJ5jMFBbekWAueyAmhyb5SjUM5kw5wbdU",
        "VoteBits": 1,
        "VoteBitsVersion": 0
    }
}

Complete the ticket purchase using the data above:

  • Import the redeem script:
$ dcrctl --testnet --wallet importscript 512102ffbb68c445608d24239c4f1435cea18a00a652d5296481123bbc40546f01415521038d980deefd1d7bee8e195204b2e00f87904ca992bf7995bca56e928c8fefc8b552ae
  • Purchase the ticket using the ticket address, fee address and fee percentage values. The dcrctl command usage is purchaseticket "fromaccount" spendlimit (minconf=1 "ticketaddress" numtickets "pooladdress" poolfees expiry "comment" ticketfee) (see the doc for details)
$ dcrctl --testnet --wallet purchaseticket "default" 100 1 TcZJ5jMFBbekWAueyAmhyb5SjUM5kw5wbdU 1 TsoWCv4btvs2276yZ9qQkNL1xv5EbrBLjAJ 7.5

@itswisdomagain itswisdomagain marked this pull request as ready for review August 7, 2019 01:03
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.

1 participant