Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chain: Use f2 code #4

Merged
merged 27 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package client

import (
"github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/rpclib"
"github.com/filecoin-project/go-lotus/jsonrpc"
)

// NewRPC creates a new http jsonrpc client.
func NewRPC(addr string) api.API {
var res api.Struct
rpclib.NewClient(addr, "Filecoin", &res.Internal)
jsonrpc.NewClient(addr, "Filecoin", &res.Internal)
return &res
}
29 changes: 29 additions & 0 deletions cborrpc/rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cborrpc

import (
"io"
"io/ioutil"

cbor "github.com/ipfs/go-ipld-cbor"
)

const MessageSizeLimit = 1 << 20

func WriteCborRPC(w io.Writer, obj interface{}) error {
data, err := cbor.DumpObject(obj)
if err != nil {
return err
}

_, err = w.Write(data)
return err
}

func ReadCborRPC(r io.Reader, out interface{}) error {
b, err := ioutil.ReadAll(r)
if err != nil {
return err
}

return cbor.DecodeInto(b, out)
}
110 changes: 110 additions & 0 deletions chain/actors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package chain

import (
"context"
"fmt"
"github.com/filecoin-project/go-lotus/chain/address"

"github.com/ipfs/go-cid"
hamt "github.com/ipfs/go-hamt-ipld"
cbor "github.com/ipfs/go-ipld-cbor"
mh "github.com/multiformats/go-multihash"
)

func init() {
cbor.RegisterCborType(InitActorState{})
cbor.RegisterCborType(AccountActorState{})
}

var AccountActorCodeCid cid.Cid
var StorageMarketActorCodeCid cid.Cid
var StorageMinerCodeCid cid.Cid
var MultisigActorCodeCid cid.Cid
var InitActorCodeCid cid.Cid

var InitActorAddress = mustIDAddress(0)
var NetworkAddress = mustIDAddress(1)
var StorageMarketAddress = mustIDAddress(2)

func mustIDAddress(i uint64) address.Address {
a, err := address.NewIDAddress(i)
if err != nil {
panic(err)
}
return a
}

func init() {
pref := cid.NewPrefixV1(cid.Raw, mh.ID)
mustSum := func(s string) cid.Cid {
c, err := pref.Sum([]byte(s))
if err != nil {
panic(err)
}
return c
}

AccountActorCodeCid = mustSum("account")
StorageMarketActorCodeCid = mustSum("smarket")
StorageMinerCodeCid = mustSum("sminer")
MultisigActorCodeCid = mustSum("multisig")
InitActorCodeCid = mustSum("init")
}

type VMActor struct {
}

type InitActorState struct {
AddressMap cid.Cid

NextID uint64
}

func (ias *InitActorState) AddActor(vmctx *VMContext, addr address.Address) (address.Address, error) {
nid := ias.NextID
ias.NextID++

amap, err := hamt.LoadNode(context.TODO(), vmctx.Ipld(), ias.AddressMap)
if err != nil {
return address.Undef, err
}

if err := amap.Set(context.TODO(), string(addr.Bytes()), nid); err != nil {
return address.Undef, err
}

if err := amap.Flush(context.TODO()); err != nil {
return address.Undef, err
}

ncid, err := vmctx.Ipld().Put(context.TODO(), amap)
if err != nil {
return address.Undef, err
}
ias.AddressMap = ncid

return address.NewIDAddress(nid)
}

func (ias *InitActorState) Lookup(cst *hamt.CborIpldStore, addr address.Address) (address.Address, error) {
amap, err := hamt.LoadNode(context.TODO(), cst, ias.AddressMap)
if err != nil {
return address.Undef, err
}

val, err := amap.Find(context.TODO(), string(addr.Bytes()))
if err != nil {
return address.Undef, err
}

ival, ok := val.(uint64)
if !ok {
return address.Undef, fmt.Errorf("invalid value in init actor state, expected uint64, got %T", val)
}

return address.NewIDAddress(ival)
}

type AccountActorState struct {
Address address.Address
}
Loading