Skip to content

Commit

Permalink
+
Browse files Browse the repository at this point in the history
  • Loading branch information
赵波 committed Aug 27, 2020
1 parent 83eb398 commit 298ca2b
Show file tree
Hide file tree
Showing 19 changed files with 524 additions and 107 deletions.
9 changes: 6 additions & 3 deletions beacon.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package filecoin

import "context"
import (
"context"
"github.com/myxtype/filecoin-client/types"
)

// BeaconGetEntry returns the beacon entry for the given filecoin epoch. If the entry has not yet been produced, the call will block until the entry becomes available
func (c *Client) BeaconGetEntry(ctx context.Context, epoch int64) (*BeaconEntry, error) {
var be *BeaconEntry
func (c *Client) BeaconGetEntry(ctx context.Context, epoch int64) (*types.BeaconEntry, error) {
var be *types.BeaconEntry
return be, c.Request(ctx, c.FilecoinMethod("BeaconGetEntry"), &be, epoch)
}
59 changes: 30 additions & 29 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,90 +3,91 @@ package filecoin
import (
"context"
"github.com/ipfs/go-cid"
"github.com/myxtype/filecoin-client/types"
"github.com/shopspring/decimal"
)

// ChainGetMessage reads a message referenced by the specified CID from the chain blockstore.
func (c *Client) ChainGetMessage(ctx context.Context, id cid.Cid) (*Message, error) {
var message *Message
func (c *Client) ChainGetMessage(ctx context.Context, id cid.Cid) (*types.Message, error) {
var message *types.Message
return message, c.Request(ctx, c.FilecoinMethod("ChainGetMessage"), &message, id)
}

// ChainGetBlockMessages returns messages stored in the specified block.
func (c *Client) ChainGetBlockMessages(ctx context.Context, id cid.Cid) (*BlockMessages, error) {
var bm *BlockMessages
func (c *Client) ChainGetBlockMessages(ctx context.Context, id cid.Cid) (*types.BlockMessages, error) {
var bm *types.BlockMessages
return bm, c.Request(ctx, c.FilecoinMethod("ChainGetBlockMessages"), &bm, id)
}

// ChainHead returns the current head of the chain.
func (c *Client) ChainHead(ctx context.Context, ) (*TipSet, error) {
var ts *TipSet
func (c *Client) ChainHead(ctx context.Context, ) (*types.TipSet, error) {
var ts *types.TipSet
return ts, c.Request(ctx, c.FilecoinMethod("ChainHead"), &ts)
}

// ChainGetTipSetByHeight looks back for a tipset at the specified epoch. If there are no blocks at the specified epoch, a tipset at an earlier epoch will be returned.
func (c *Client) ChainGetTipSetByHeight(ctx context.Context, height int64, tsk TipSetKey) (*TipSet, error) {
var ts *TipSet
func (c *Client) ChainGetTipSetByHeight(ctx context.Context, height int64, tsk types.TipSetKey) (*types.TipSet, error) {
var ts *types.TipSet
return ts, c.Request(ctx, c.FilecoinMethod("ChainGetTipSetByHeight"), &ts, height, tsk)
}

// ChainExport returns a stream of bytes with CAR dump of chain data.
func (c *Client) ChainExport(ctx context.Context, tsk TipSetKey) ([]byte, error) {
func (c *Client) ChainExport(ctx context.Context, tsk types.TipSetKey) ([]byte, error) {
var result []byte
return result, c.Request(ctx, c.FilecoinMethod("ChainExport"), &result, tsk)
}

// ChainGetBlock returns the block specified by the given CID.
func (c *Client) ChainGetBlock(ctx context.Context, id cid.Cid) (*BlockHeader, error) {
var bh *BlockHeader
func (c *Client) ChainGetBlock(ctx context.Context, id cid.Cid) (*types.BlockHeader, error) {
var bh *types.BlockHeader
return bh, c.Request(ctx, c.FilecoinMethod("ChainGetBlock"), &bh, id)
}

// ChainGetGenesis returns the genesis tipset.
func (c *Client) ChainGetGenesis(ctx context.Context) (*TipSet, error) {
var ts *TipSet
func (c *Client) ChainGetGenesis(ctx context.Context) (*types.TipSet, error) {
var ts *types.TipSet
return ts, c.Request(ctx, c.FilecoinMethod("ChainGetGenesis"), &ts)
}

// ChainGetNode
func (c *Client) ChainGetNode(ctx context.Context, p string) (*IpldObject, error) {
var ipld *IpldObject
func (c *Client) ChainGetNode(ctx context.Context, p string) (*types.IpldObject, error) {
var ipld *types.IpldObject
return ipld, c.Request(ctx, c.FilecoinMethod("ChainGetNode"), &ipld, p)
}

// ChainGetParentMessages returns messages stored in parent tipset of the specified block.
func (c *Client) ChainGetParentMessages(ctx context.Context, id cid.Cid) ([]Message, error) {
var msgs []Message
func (c *Client) ChainGetParentMessages(ctx context.Context, id cid.Cid) ([]types.Message, error) {
var msgs []types.Message
return msgs, c.Request(ctx, c.FilecoinMethod("ChainGetParentMessages"), &msgs, id)
}

// ChainGetParentReceipts returns receipts for messages in parent tipset of the specified block.
func (c *Client) ChainGetParentReceipts(ctx context.Context, id cid.Cid) ([]*MessageReceipt, error) {
var mrs []*MessageReceipt
func (c *Client) ChainGetParentReceipts(ctx context.Context, id cid.Cid) ([]*types.MessageReceipt, error) {
var mrs []*types.MessageReceipt
return mrs, c.Request(ctx, c.FilecoinMethod("ChainGetParentReceipts"), &mrs, id)
}

// ChainGetPath returns a set of revert/apply operations needed to get from one tipset to another
func (c *Client) ChainGetPath(ctx context.Context, from TipSetKey, to TipSetKey) (*HeadChange, error) {
var hc *HeadChange
func (c *Client) ChainGetPath(ctx context.Context, from types.TipSetKey, to types.TipSetKey) (*types.HeadChange, error) {
var hc *types.HeadChange
return hc, c.Request(ctx, c.FilecoinMethod("ChainGetPath"), &hc, from, to)
}

// ChainGetRandomnessFromBeacon is used to sample the beacon for randomness.
func (c *Client) ChainGetRandomnessFromBeacon(ctx context.Context, tsk TipSetKey, personalization int64, randEpoch int64, entropy []byte) ([]byte, error) {
func (c *Client) ChainGetRandomnessFromBeacon(ctx context.Context, tsk types.TipSetKey, personalization int64, randEpoch int64, entropy []byte) ([]byte, error) {
var result []byte
return result, c.Request(ctx, c.FilecoinMethod("ChainGetRandomnessFromBeacon"), &result, tsk, personalization, randEpoch, entropy)
}

// ChainGetRandomnessFromTickets is used to sample the chain for randomness.
func (c *Client) ChainGetRandomnessFromTickets(ctx context.Context, tsk TipSetKey, personalization int64, randEpoch int64, entropy []byte) ([]byte, error) {
func (c *Client) ChainGetRandomnessFromTickets(ctx context.Context, tsk types.TipSetKey, personalization int64, randEpoch int64, entropy []byte) ([]byte, error) {
var result []byte
return result, c.Request(ctx, c.FilecoinMethod("ChainGetRandomnessFromTickets"), &result, tsk, personalization, randEpoch, entropy)
}

// ChainGetTipSet returns the tipset specified by the given TipSetKey.
func (c *Client) ChainGetTipSet(ctx context.Context, tsk TipSetKey) (*TipSet, error) {
var ts *TipSet
func (c *Client) ChainGetTipSet(ctx context.Context, tsk types.TipSetKey) (*types.TipSet, error) {
var ts *types.TipSet
return ts, c.Request(ctx, c.FilecoinMethod("ChainGetTipSet"), &ts, tsk)
}

Expand All @@ -108,18 +109,18 @@ func (c *Client) ChainReadObj(ctx context.Context, obj cid.Cid) ([]byte, error)
}

// ChainSetHead forcefully sets current chain head. Use with caution.
func (c *Client) ChainSetHead(ctx context.Context, tsk TipSetKey) error {
func (c *Client) ChainSetHead(ctx context.Context, tsk types.TipSetKey) error {
return c.Request(ctx, c.FilecoinMethod("ChainSetHead"), nil, tsk)
}

// ChainStatObj returns statistics about the graph referenced by 'obj'. If 'base' is also specified, then the returned stat will be a diff between the two objects.
func (c *Client) ChainStatObj(ctx context.Context, obj, base cid.Cid) (ObjStat, error) {
var os ObjStat
func (c *Client) ChainStatObj(ctx context.Context, obj, base cid.Cid) (types.ObjStat, error) {
var os types.ObjStat
return os, c.Request(ctx, c.FilecoinMethod("ChainStatObj"), &os, obj, base)
}

// ChainTipSetWeight computes weight for the specified tipset.
func (c *Client) ChainTipSetWeight(ctx context.Context, tsk TipSetKey) (decimal.Decimal, error) {
func (c *Client) ChainTipSetWeight(ctx context.Context, tsk types.TipSetKey) (decimal.Decimal, error) {
var d decimal.Decimal
return d, c.Request(ctx, c.FilecoinMethod("ChainTipSetWeight"), &d, tsk)
}
33 changes: 33 additions & 0 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package crypto

import (
"fmt"
"math"
)

type SigType byte

const (
SigTypeUnknown = SigType(math.MaxUint8)

SigTypeSecp256k1 = SigType(iota) // Most
SigTypeBLS
)

func (t SigType) Name() (string, error) {
switch t {
case SigTypeUnknown:
return "unknown", nil
case SigTypeSecp256k1:
return "secp256k1", nil
case SigTypeBLS:
return "bls", nil
default:
return "", fmt.Errorf("invalid signature type: %d", t)
}
}

type Signature struct {
Type SigType `json:"Type"`
Data []byte `json:"Data"`
}
7 changes: 4 additions & 3 deletions gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package filecoin
import (
"context"
"github.com/ipfs/go-cid"
"github.com/myxtype/filecoin-client/types"
)

// GasEstimateGasLimit estimates gas used by the message and returns it. It fails if message fails to execute.
func (c *Client) GasEstimateGasLimit(ctx context.Context, message *Message, cids []*cid.Cid) (int64, error) {
func (c *Client) GasEstimateGasLimit(ctx context.Context, message *types.Message, cids []*cid.Cid) (int64, error) {
var gasLimit int64
return gasLimit, c.Request(ctx, c.FilecoinMethod("GasEstimateGasLimit"), &gasLimit, message, cids)
}

// GasEstimateMessageGas estimates gas values for unset message gas fields
func (c *Client) GasEstimateMessageGas(ctx context.Context, message *Message, spec *MessageSendSpec, cids []*cid.Cid) (*Message, error) {
var msg *Message
func (c *Client) GasEstimateMessageGas(ctx context.Context, message *types.Message, spec *types.MessageSendSpec, cids []*cid.Cid) (*types.Message, error) {
var msg *types.Message
return msg, c.Request(ctx, c.FilecoinMethod("GasEstimateMessageGas"), &msg, message, spec, cids)
}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ go 1.15

require (
github.com/filecoin-project/go-address v0.0.3
github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-ipfs-util v0.0.1
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/multiformats/go-multihash v0.0.14
github.com/shopspring/decimal v1.2.0
github.com/supranational/blst v0.1.1
)
Loading

0 comments on commit 298ca2b

Please sign in to comment.