shrub/base/ape/bit.hoon

206 lines
6.1 KiB
Plaintext
Raw Normal View History

2015-05-07 00:00:06 +03:00
::
::
::::
::
/? 314
2015-05-29 02:07:03 +03:00
/- *talk, *bit-api
/+ talk, sole, http, mean
2015-05-07 00:00:06 +03:00
!:
2015-05-08 00:33:18 +03:00
:::: sivtyv-barnel
2015-05-08 02:53:08 +03:00
:: be sure to have oauth2-code markk
2015-05-07 00:00:06 +03:00
|%
++ axle
2015-05-29 02:07:03 +03:00
$: cred=(unit ,[app-secret=@t client-id=@t])
oauth-code=(unit ,@t)
auth=(unit ,[access=@t refresh=@t])
contacts=(map ,@t ,@t)
2015-05-08 00:33:18 +03:00
outgoing=(map ship ,@t) incoming=(map ,@t ship)
2015-05-07 00:00:06 +03:00
==
2015-05-13 22:46:25 +03:00
++ move ,[bone note]
++ hapt ,[ship path]
++ note
2015-05-13 22:46:25 +03:00
$% [%send wire [ship term] %poke mesa]
[%them wire (unit hiss)]
2015-05-29 02:07:03 +03:00
[%hiss wire mark bit-any]
==
++ gift
$% [%nice ~]
[%mean ares]
==
2015-05-07 00:00:06 +03:00
++ sign
$% [%thou p=httr]
2015-05-13 22:46:25 +03:00
[%unto %coup p=(unit tang)]
==
++ mesa
$% [%bit-addr-request ~]
[%bit-addr-made @t]
[%talk-command command]
2015-05-07 00:00:06 +03:00
==
--
::
!:
2015-05-28 06:48:25 +03:00
|_ [hid=bowl vat=axle]
:: ++ prep ~&(%bit-prep-wipe ,_`.)
2015-05-29 02:07:03 +03:00
++ return [*(list move) .]
++ redirect-uri [hostname `/~~/home/pub/bit/fab ~]
++ hostname ^- hart
2015-05-08 02:27:50 +03:00
?+ (clan our.hid) !!
2015-06-04 03:29:56 +03:00
%czar [| ?+(our.hid `8.443 %~fyr `8.444) `/localhost]
%duke [| `8.444 `/org/urbit/(crip +:<our.hid>)]
2015-05-08 02:27:50 +03:00
==
++ auth-url
2015-06-04 03:29:56 +03:00
%+ weld "https://sandbox.coinbase.com/oauth/authorize"
%- tail:earn :~
'response_type'^%code
2015-05-29 02:07:03 +03:00
'client_id'^client-id:(need cred.vat)
'redirect_uri'^(crip (earn redirect-uri))
'scope'^'user balance buy sell send transactions addresses'
'meta[send_limit_amount]'^'1'
'meta[send_limit_curency]'^'BTC'
'meta[send_limit_period]'^'day'
==
2015-05-29 02:07:03 +03:00
++ old-api
|= [pour-path=wire end-point=path req=$|(%get [%post p=json])]
^- move
%^ httpreq ost.hid pour-path
2015-05-29 02:07:03 +03:00
[/com/coinbase/api v1/end-point req ~ ['access_token' access:(need auth.vat)]~]
::
++ api-call
|= [res=mark req=bit-api-call] ^+ return
2015-05-29 02:07:03 +03:00
~| %missing-access-token
[[ost.hid %hiss / res bit-api-call/[access:(need auth.vat) req]]~ +>.$]
::
++ print |=(msg=tape [[(publish [%lin & (crip msg)]~)]~ +>.$])
++ callback-uri [hostname [`%json /~/to/[dap.hid]/json] ~[anon/'' wire/'/']]
2015-05-07 00:00:06 +03:00
++ poke-auth
|= arg=[secr=cord id=cord]
2015-05-29 02:07:03 +03:00
=. cred.vat `arg
2015-05-07 00:00:06 +03:00
=+ prl=`purl`(need (epur (crip auth-url)))
:_ +>.$
:- %- publish
2015-05-13 22:46:25 +03:00
:~ [%lin & 'secret and client id saved successfully']
[%lin & 'please click on the url below to continue authentication']
2015-06-03 21:44:40 +03:00
[%url prl ~]
2015-05-13 22:46:25 +03:00
==
2015-05-07 00:00:06 +03:00
~
::
2015-05-29 22:27:09 +03:00
++ sigh-tang |=([* err=tang] (mean err))
2015-05-13 22:46:25 +03:00
++ send-friend :: inter-app interface
|= [way=wire his=ship mez=$%([%bit-addr-request ~] [%bit-addr-made @t])]
^- move
[ost.hid %send way [his dap.hid] %poke mez]
2015-05-29 02:07:03 +03:00
::
++ poke-bit-send |=(req=bit-send (api-call %bit-transaction send/req))
2015-05-29 02:07:03 +03:00
++ sigh-bit-transaction
|=([* trid=@t] (print "transaction success {(trip trid)}"))
::
++ poke-bit-ship-send :: send to ship
2015-05-28 09:51:32 +03:00
|= [to=ship amount=@t]
=. outgoing.vat (~(put by outgoing.vat) to amount)
:_ +>.$
2015-05-13 22:46:25 +03:00
:_ ~
(send-friend /sent to %bit-addr-request ~)
++ poke-bit-addr-request :: give your address to receive bit
|= ~ :: gen new address with callback
:_ +>.$
2015-05-13 22:46:25 +03:00
:_ ~
%+ old-api /addr-request/(scot %p src.hid)
:+ /addresses %post
%+ joba %address
%- jobe :~
label/(jape "address for {<src.hid>}")
2015-05-29 02:07:03 +03:00
'callback_url'^(jape (earn callback-uri))
==
::
++ pour-addr-request :: send new address to sender
|= [pax=path rez=json]
2015-05-08 00:33:18 +03:00
=+ adr=(need ((ot address/so ~):jo rez))
=+ his=(slav %p +<.pax)
~! incoming.vat
=. incoming.vat
(~(put by incoming.vat) adr his)
:_ +>.$
:_ ~
(send-friend [%message ~] his %bit-addr-made adr)
::
++ poke-bit-addr-made :: receive address for sending
|= addr=@t
=+ amount=(~(got by outgoing.vat) src.hid) :: get amount to send
(api-call %bit-transaction txt-send/[addr amount])
2015-05-29 02:07:03 +03:00
::
2015-05-07 00:00:06 +03:00
++ poke-oauth2-code
|= code=cord
2015-05-07 00:00:06 +03:00
=. oauth-code.vat
[~ code]
2015-05-29 02:07:03 +03:00
?< ?=(~ cred.vat)
=+ req=[code [client-id app-secret]:u.cred.vat redirect-uri]
[[ost.hid %hiss / %oauth-tokens bit-get-token/req]~ +>.$]
2015-05-29 02:07:03 +03:00
::
++ sigh-oauth-tokens
|= [wire toke=[access=@t refresh=@t]]
=.(auth.vat `toke (print "authenticated."))
2015-05-29 02:07:03 +03:00
::
2015-05-07 00:00:06 +03:00
++ poke-buy
|=(arg=[amount=@t currency=@t] ?<(=(amount.arg ~) (api-call %json %buy arg)))
2015-05-07 00:00:06 +03:00
++ poke-sell
|=(arg=[amount=@t currency=@t] ?<(=(amount.arg ~) (api-call %json %sell arg)))
2015-05-29 22:27:09 +03:00
++ sigh-json |=([* a=json] ~&(a return))
++ poke-list |=(~ (api-call %bit-accounts %list ~))
2015-05-29 22:27:09 +03:00
++ sigh-bit-accounts |=([* acc=bit-accounts] ~&(accounts=acc return))
++ poke-send-raw
2015-05-28 09:51:32 +03:00
|= arg=[to=@t amone=(unit ,@t) cur=(unit ,@t) amtwo=(unit ,@t) nt=(unit ,@t)]
2015-05-29 02:07:03 +03:00
=+ adr=?~((~(get by contacts.vat) to.arg) to ~&('contact-exists' (~(get by contacts.vat) to.arg)))
2015-05-07 00:00:06 +03:00
=+ ^= info
?~ cur.arg
[to/s/to.arg amount/s/(need amone.arg) ~]
?~ nt.arg
[to/s/to.arg 'amount_currency_iso'^s/(need cur.arg) 'amount_string'^s/(need amtwo.arg) ~]
[to/s/to.arg amount/s/(need amtwo.arg) 'amount_string'^s/(need amtwo.arg) ~]
=+ ^= pst
2015-05-29 02:07:03 +03:00
(jobe transaction/(jobe info) ~)
[[(old-api /send /transactions/'send_money' %post pst) ~] +>.$]
2015-05-07 09:49:30 +03:00
::
++ poke-json
|= arg=json
~& arg
=+ [adr amo]=(need %.(arg (ot address/so amount/no ~):jo))
=+ frm=(~(get by incoming.vat) adr)
(print "just received {(trip amo)} BTC from {<frm>}")
::(old-api /get-id /transactions/[transaction-id] %get)
++ pour-get-id :: display transaction info
|= [pax=path rez=json]
:_ +>.$
:_ ~
!!
::
2015-05-13 23:17:38 +03:00
++ thou
2015-05-28 09:51:32 +03:00
|= [way=wire res=httr]
2015-05-13 23:17:38 +03:00
?+ -.way !!
%message `+>.$
?(%addr-request %get-id)
~| 'must receive a 200'
~| res
2015-05-13 23:17:38 +03:00
?> =(200 p.res)
%- ?-(-.way %addr-request pour-addr-request, %get-id pour-get-id)
[way (rash q:(need r.res) apex:poja)]
2015-05-07 00:00:06 +03:00
==
::
++ publish
|= act=(list speech)
^- move
2015-05-13 22:46:25 +03:00
=+ ^= thotz
2015-05-07 09:49:30 +03:00
%+ turn act
2015-05-13 22:46:25 +03:00
|= sp=speech ^- thought
2015-05-07 09:49:30 +03:00
=+ ^= tail
:- ^- audience
2015-05-08 02:25:22 +03:00
:+ :- `partner`[%& our.hid ?+((clan our.hid) !! %czar %court, %duke %porch)]
2015-05-07 09:49:30 +03:00
^- (pair envelope delivery)
[`envelope`[& ~] %pending]
~
2015-05-07 00:00:06 +03:00
~
2015-05-28 06:54:20 +03:00
`statement`[now.hid ~ sp]
2015-05-07 09:49:30 +03:00
:- `@`(sham eny.hid tail)
tail
[ost.hid %send /auth [our.hid %talk] %poke [%talk-command %publish thotz]]
2015-05-07 00:00:06 +03:00
--