Created
October 20, 2020 20:24
-
-
Save mikeal/879a6d5b3e32360ffe0c0c41fa8e2c9a to your computer and use it in GitHub Desktop.
Filecoin Liftoff
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
import * as Block from 'multiformats/block' | |
import { sha256 as hasher } from 'multiformats/hashes/sha2' | |
import * as codec from '@ipld/dag-cbor' | |
import { CID } from 'multiformats' | |
let value = { hello: 'world' } | |
let hello = await Block.encode({ value, codec, hasher }) | |
let bbbb = await Block.encode({ value: { foo: hello.cid }, codec, hasher }) | |
let cccc = await Block.encode({ value: { bar: hello.cid, prop: 31337 }, codec, hasher }) | |
let dddd = await Block.encode({ value: { one: bbbb.cid, two: cccc.cid }, codec, hasher }) | |
const putBlock = async (ipfs, block) => { | |
const opts = { cid: block.cid.toString() } | |
await ipfs.block.put(block.bytes, opts) | |
return true | |
} | |
const getBlock = async (ipfs, cid) => { | |
const { data } = await ipfs.block.get(cid.toString()) | |
return Block.create({ bytes: data, cid, codec, hasher }) | |
} |
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
import * as Block from 'multiformats/block' | |
import { sha256 as hasher } from 'multiformats/hashes/sha2' | |
import * as codec from '@ipld/dag-cbor' | |
import { CID } from 'multiformats' | |
let value = { hello: 'world' } | |
let hello = await Block.encode({ value, codec, hasher }) | |
// hello.bytes - encoded binary data | |
// hello.cid - CID address | |
let bbbb = await Block.encode({ value: { foo: hello.cid }, codec, hasher }) | |
let cccc = await Block.encode({ value: { bar: hello.cid, prop: 31337 }, codec, hasher }) | |
let dddd = await Block.encode({ value: { one: bbbb.cid, two: cccc.cid }, codec, hasher }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment