0.5.0-u20.0 • Published 1 year ago

@agoric/casting v0.5.0-u20.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 year ago

Agoric Casting

This Agoric Casting package follows ocap broadcasts in a flexible, future-proof way.

TL;DR: You can run yarn demo, or to follow a mailbox castingSpec do:

npx agoric follow -Bhttp://devnet.agoric.net/network-config :mailbox.agoric1foobarbaz -otext

An example of following an on-chain mailbox in code (using this package) is:

// First, obtain a Hardened JS environment via Endo.
import '@endo/init/pre-remoting.js'; // needed only for the next line
import '@agoric/castingSpec/node-fetch-shim.js'; // needed for Node.js
import '@endo/init';

import {
  iterateLatest,
  makeFollower,
  makeLeader,
  makeCastingSpec,
} from '@agoric/casting';

// Iterate over a mailbox follower on the devnet.
const leader = makeLeader('https://devnet.agoric.net/network-config');
const castingSpec = makeCastingSpec(':mailbox.agoric1foobarbaz');
const follower = makeFollower(leader, castingSpec);
for await (const { value } of iterateLatest(follower)) {
  console.log(`here's a mailbox value`, value);
}

Follower options

The followerOpts argument in makeFollower(leader, key, followerOpts) provides an optional bag of options:

  • the integrity option, which has three possibilities:
    • 'strict' - release data only after proving it was validated (may incur waits for one block's data to be validated in the next block),
    • 'optimistic' (default) - release data immediately, but may crash the follower in the future if an already-released value could not be proven,
    • 'none' - release data immediately without validation
  • the decode option is a function to translate buf: Uint8Array into data: string
    • (default) - interpret buf as a utf-8 string, then JSON.parse it
  • the unserializer option can be
    • (default) - release unserialized objects using @agoric/marshal's makeMarshal()
    • null - don't additionally unserialize data before releasing it
    • any unserializer object supporting E(unserializer).unserialize(data)
  • the crasher option can be
    • null (default) follower failures only propagate an exception/rejection
    • any crasher object supporting E(crasher).crash(reason)

Behind the scenes

  • the network config contains enough information to obtain Tendermint RPC nodes for a given Agoric network. You can use makeLeaderFromRpcAddresses directly if you want to avoid fetching a network-config.
  • each follower uses periodic CosmJS state polling (every X milliseconds) which can be refreshed more expediently via a Tendermint subscription to the corresponding state_change event
  • published (string) values are automatically unmarshalled, but without object references. a custom marshaller for your application.
  • the iterateRecent adapter transforms a follower into a local async iterator that produces only the last queried value (with no history reconstruction)

Status

This package currently depends on:

Short-term goals:

0.5.0-u20.0

1 year ago

0.4.3-u18.5

1 year ago

0.4.3-u18.4

2 years ago

0.4.3-u18.3

2 years ago

0.4.3-u18.2

2 years ago

0.4.3-u18.1

2 years ago

0.4.3-u18.0

2 years ago

0.4.3-u18a.0

1 year ago

0.4.3-u19.2

1 year ago

0.4.3-u19.1

1 year ago

0.4.3-u19.0

1 year ago

0.4.3-u17.1

2 years ago

0.4.3-u17.0

2 years ago

0.4.3-u16.2

2 years ago

0.4.3-u16.1

2 years ago

0.4.3-u16.0

2 years ago

0.4.3-u13.0

3 years ago

0.4.3-u14.0

2 years ago

0.4.3-u12.0

3 years ago

0.4.3-u11wf.0

3 years ago

0.4.3-u11.0

3 years ago

0.4.2

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.3.4

3 years ago

0.3.2

4 years ago

0.3.3

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.0

4 years ago