-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from storacha-network/feat/receipt-writing
Receipt writing
- Loading branch information
Showing
18 changed files
with
507 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package delegation | ||
|
||
import ( | ||
"github.com/web3-storage/go-ucanto/core/dag/blockstore" | ||
"github.com/web3-storage/go-ucanto/core/ipld" | ||
"github.com/web3-storage/go-ucanto/ucan" | ||
) | ||
|
||
type Proof struct { | ||
delegation Delegation | ||
link ucan.Link | ||
} | ||
|
||
func (p Proof) Delegation() (Delegation, bool) { | ||
return p.delegation, p.delegation != nil | ||
} | ||
|
||
func (p Proof) Link() ucan.Link { | ||
if p.delegation != nil { | ||
return p.delegation.Link() | ||
} | ||
return p.link | ||
} | ||
|
||
func FromDelegation(delegation Delegation) Proof { | ||
return Proof{delegation, nil} | ||
} | ||
|
||
func FromLink(link ucan.Link) Proof { | ||
return Proof{nil, link} | ||
} | ||
|
||
type Proofs []Proof | ||
|
||
func NewProofsView(links []ipld.Link, bs blockstore.BlockReader) Proofs { | ||
proofs := make(Proofs, 0, len(links)) | ||
for _, link := range links { | ||
if delegation, err := NewDelegationView(link, bs); err == nil { | ||
proofs = append(proofs, FromDelegation(delegation)) | ||
} else { | ||
proofs = append(proofs, FromLink(link)) | ||
} | ||
} | ||
return proofs | ||
} | ||
|
||
// WriteInto writes a set of proofs, some of which may be full delegations to a blockstore | ||
func (proofs Proofs) WriteInto(bs blockstore.BlockWriter) ([]ipld.Link, error) { | ||
links := make([]ucan.Link, 0, len(proofs)) | ||
for _, p := range proofs { | ||
links = append(links, p.Link()) | ||
if delegation, isDelegation := p.Delegation(); isDelegation { | ||
err := blockstore.WriteInto(delegation, bs) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
} | ||
return links, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ import ( | |
|
||
type Link = ipld.Link | ||
type Block = block.Block | ||
type Node = ipld.Node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
type Result union { | ||
| any "ok" | ||
| any "error" | ||
} representation keyed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.