Add bitswap calls.

This commit is contained in:
Jaidyn Levesque 2019-06-06 19:39:10 -05:00
parent 20a7eaf558
commit a612e6d6d7
2 changed files with 58 additions and 20 deletions

View File

@ -58,9 +58,8 @@
;; FORM FORM → FORM ;; FORM FORM → FORM
(defmacro bind-api-result (call form) (defmacro bind-api-result (call form)
"Wrap around an #'ipfs-call form; if #'call returns an error, then "Wrap around an #'ipfs-call form; if #'call returns an error, then return NIL
return NIL and the error message-- (NIL STRING)-- otherwise, execute and the error message-- (NIL STRING)-- otherwise, execute #'form.
#'form.
Binds the result of the API call to you guessed it, the variable 'result'. Binds the result of the API call to you guessed it, the variable 'result'.
The error message is assigned to 'message', if such a thing exists." The error message is assigned to 'message', if such a thing exists."
`(multiple-value-bind (result message) `(multiple-value-bind (result message)
@ -172,10 +171,45 @@
;; —————————————————————————————————————
;; BITSWAP CALLS
;; STRING → ALIST || (NIL STRING)
(defun bitswap/ledger (peer-id)
"Show the current ledger for a peer.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bitswap-ledger"
(bind-api-alist
(ipfs-call "bitswap/ledger" `(("arg" ,peer-id)))
result))
;; NIL → NIL
(defun bitswap/reprovide ()
"Trigger the reprovider.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bitswap-reprovide"
(ipfs-call "bitswap/reprovide" '()))
;; NIL → ALIST || (NIL STRING)
(defun bitswap/stat ()
"Show diagnostic info on the bitswap agent.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bitswap-stat"
(bind-api-alist
(ipfs-call "bitswap/stat" '())
result))
;; STRING → ALIST || (NIL STRING)
(defun bitswap/wantlist (&optional peer-id)
"Show blocks currently on the wantlist.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bitswap-wantlist"
(bind-api-alist
(ipfs-call "bitswap/wantlist" `(,(if peer-id (list "peer" peer-id))))
result))
;; ————————————————————————————————————— ;; —————————————————————————————————————
;; BLOCK CALLS ;; BLOCK CALLS
;; STRING → STRING ;; STRING → STRING || (NIL STRING)
(defun block/get (hash) (defun block/get (hash)
"Get a raw IPFS block. "Get a raw IPFS block.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-block-get" /ipns/docs.ipfs.io/reference/api/http/#api-v0-block-get"
@ -183,43 +217,41 @@
(ipfs-call "block/get" `(("arg" ,hash))) (ipfs-call "block/get" `(("arg" ,hash)))
result)) result))
;; PATHNAME [:STRING :STRING :NUMBER :BOOLEAN] → (STRING NUMBER) ;; PATHNAME [:STRING :STRING :NUMBER :BOOLEAN] → ALIST || (NIL STRING)
(defun block/put (pathname &key (format nil) (mhtype "sha2-256") (mhlen -1) (defun block/put (pathname &key (format nil) (mhtype "sha2-256") (mhlen -1)
(pin nil)) (pin nil))
"Store input as an IPFS block. "Store input as an IPFS block.
/ipns/docs.ipfs.io/reference/api/http/#api-v0-block-put" /ipns/docs.ipfs.io/reference/api/http/#api-v0-block-put"
(bind-api-result (bind-api-alist
(ipfs-call "block/put" `(,(if format (list "format" format)) (ipfs-call "block/put" `(,(if format (list "format" format))
("mhtype" ,mhtype) ("mhtype" ,mhtype)
("mhlen" ,mhlen) ("mhlen" ,mhlen)
("pin" ,pin)) ("pin" ,pin))
:method :POST :parameters `(("data" . ,pathname))) :method :POST :parameters `(("data" . ,pathname)))
(values (gethash "Key" result) result))
(gethash "Size" result))))
;; STRING → BOOLEAN ;; STRING → NIL
(defun block/rm (hash &key (force nil)) (defun block/rm (hash &key (force nil))
"Delete an IPFS block(s). "Delete an IPFS block(s).
/ipns/docs.ipfs.io/reference/api/http/#api-v0-block-rm" /ipns/docs.ipfs.io/reference/api/http/#api-v0-block-rm"
(bind-api-result (bind-api-result
(ipfs-call "block/rm" `(("arg" ,hash) ,(if force (list "force" force)))) (ipfs-call "block/rm" `(("arg" ,hash) ,(if force (list "force" force))))
't)) nil))
;; STRING → (STRING NUMBER) ;; STRING → ALIST || (NIL STRING)
(defun block/stat (hash) (defun block/stat (hash)
"Print info about a raw IPFS block "Print info about a raw IPFS block
/ipns/docs.ipfs.io/reference/api/http/#api-v0-block-stat" /ipns/docs.ipfs.io/reference/api/http/#api-v0-block-stat"
(bind-api-result (bind-api-alist
(ipfs-call "block/stat" `(("arg" ,hash))) (ipfs-call "block/stat" `(("arg" ,hash)))
(values (gethash "Key" result) result))
(gethash "Size" result))))
;; ————————————————————————————————————— ;; —————————————————————————————————————
;; BOOTSTRAP CALLS ;; BOOTSTRAP CALLS
;; NIL → LIST ;; NIL → LIST || (NIL STRING)
(defun bootstrap () (defun bootstrap ()
"Return a list of bootstrap peers "Return a list of bootstrap peers
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap" /ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap"
@ -227,13 +259,13 @@
(ipfs-call "bootstrap" '()) (ipfs-call "bootstrap" '())
(gethash "Peers" result))) (gethash "Peers" result)))
;; NIL → LIST ;; NIL → LIST || (NIL STRING)
(defun bootstrap/list () (defun bootstrap/list ()
"Return a list of bootstrap peers "Return a list of bootstrap peers
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-list" /ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-list"
(bootstrap)) (bootstrap))
;; STRING → LIST ;; STRING → LIST || (NIL STRING)
(defun bootstrap/add (peer) (defun bootstrap/add (peer)
"Add a peer to the bootstrap list "Add a peer to the bootstrap list
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-add" /ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-add"
@ -241,7 +273,7 @@
(ipfs-call "bootstrap/add" `(("arg" ,peer))) (ipfs-call "bootstrap/add" `(("arg" ,peer)))
(gethash "Peers" result))) (gethash "Peers" result)))
;; NIL → LIST ;; NIL → LIST || (NIL STRING)
(defun bootstrap/add/default () (defun bootstrap/add/default ()
"Add default peers to the bootstrap list "Add default peers to the bootstrap list
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-add-default" /ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-add-default"
@ -249,7 +281,7 @@
(ipfs-call "bootstrap/add/default" '()) (ipfs-call "bootstrap/add/default" '())
(gethash "Peers" result))) (gethash "Peers" result)))
;; STRING → LIST ;; STRING → LIST || (NIL STRING)
(defun bootstrap/rm (peer) (defun bootstrap/rm (peer)
"Remove a peer from the bootstrap list "Remove a peer from the bootstrap list
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-rm" /ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-rm"
@ -257,7 +289,7 @@
(ipfs-call "bootstrap/rm" `(("arg" ,peer))) (ipfs-call "bootstrap/rm" `(("arg" ,peer)))
(gethash "Peers" result))) (gethash "Peers" result)))
;; NIL → LIST ;; NIL → LIST || (NIL STRING)
(defun bootstrap/rm/all (peer) (defun bootstrap/rm/all (peer)
"Remove a peer from the bootstrap list "Remove a peer from the bootstrap list
/ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-rm" /ipns/docs.ipfs.io/reference/api/http/#api-v0-bootstrap-rm"

View File

@ -15,6 +15,12 @@
:resolve :resolve
:shutdown :shutdown
;; / bitswap calls
:bitswap/ledger
:bitswap/reprovide
:bitswap/stat
:bitswap/wantlist
;; / block calls ;; / block calls
:block/get :block/get
:block/put :block/put