github.com/storacha/go-ucanto@v0.7.2/core/receipt/ran/ran.go (about) 1 package ran 2 3 import ( 4 "github.com/storacha/go-ucanto/core/dag/blockstore" 5 "github.com/storacha/go-ucanto/core/invocation" 6 "github.com/storacha/go-ucanto/core/ipld" 7 "github.com/storacha/go-ucanto/ucan" 8 ) 9 10 type Ran struct { 11 invocation invocation.Invocation 12 link ucan.Link 13 } 14 15 func (r Ran) Invocation() (invocation.Invocation, bool) { 16 return r.invocation, r.invocation != nil 17 } 18 19 func (r Ran) Link() ucan.Link { 20 if r.invocation != nil { 21 return r.invocation.Link() 22 } 23 return r.link 24 } 25 26 func FromInvocation(invocation invocation.Invocation) Ran { 27 return Ran{invocation, nil} 28 } 29 30 func FromLink(link ucan.Link) Ran { 31 return Ran{nil, link} 32 } 33 34 func (r Ran) WriteInto(bs blockstore.BlockWriter) (ipld.Link, error) { 35 if invocation, ok := r.Invocation(); ok { 36 return r.Link(), blockstore.WriteInto(invocation, bs) 37 } 38 return r.Link(), nil 39 }