Skip to content

Commit

Permalink
Add support for Filecoin.StateMarketStorageDeal and use abi primitives
Browse files Browse the repository at this point in the history
Add support for getting the status of a deal via
`Filecoin.StateMarketStorageDeal` call.

Change responses to use standard types from `abi` package.
  • Loading branch information
masih committed Aug 24, 2023
1 parent 3a2a0c7 commit 37d0451
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Filecoin API interactions provided by Telefil are:
- **`Filecoin.StateDealProviderCollateralBounds`**
- **`Filecoin.StateListMiners`**
- **`Filecoin.StateMinerPower`**
- **`Filecoin.StateMarketStorageDeal`**

## Installation

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ require (

require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/filecoin-project/go-amt-ipld/v4 v4.0.0 // indirect
github.com/filecoin-project/go-bitfield v0.2.4 // indirect
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0 // indirect
github.com/ipfs/go-block-format v0.0.3 // indirect
github.com/ipfs/go-cid v0.4.1 // indirect
github.com/ipfs/go-ipfs-util v0.0.2 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ github.com/filecoin-project/go-address v0.0.5/go.mod h1:jr8JxKsYx+lQlQZmF5i2U0Z+
github.com/filecoin-project/go-address v1.1.0 h1:ofdtUtEsNxkIxkDw67ecSmvtzaVSdcea4boAmLbnHfE=
github.com/filecoin-project/go-address v1.1.0/go.mod h1:5t3z6qPmIADZBtuE9EIzi0EwzcRy2nVhpo0I/c1r0OA=
github.com/filecoin-project/go-amt-ipld/v2 v2.1.0/go.mod h1:nfFPoGyX0CU9SkXX8EoCcSuHN1XcbN0c6KBh7yvP5fs=
github.com/filecoin-project/go-amt-ipld/v4 v4.0.0 h1:XM81BJ4/6h3FV0WfFjh74cIDIgqMbJsMBLM0fIuLUUk=
github.com/filecoin-project/go-amt-ipld/v4 v4.0.0/go.mod h1:gF053YQ4BIpzTNDoEwHZas7U3oAwncDVGvOHyY8oDpE=
github.com/filecoin-project/go-bitfield v0.2.0/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM=
github.com/filecoin-project/go-bitfield v0.2.4 h1:uZ7MeE+XfM5lqrHJZ93OnhQKc/rveW8p9au0C68JPgk=
github.com/filecoin-project/go-bitfield v0.2.4/go.mod h1:CNl9WG8hgR5mttCnUErjcQjGvuiZjRqK9rHVBsQF4oM=
github.com/filecoin-project/go-commp-utils v0.1.3/go.mod h1:3ENlD1pZySaUout0p9ANQrY3fDFoXdqyX04J+dWpK30=
github.com/filecoin-project/go-commp-utils/nonffi v0.0.0-20220905160352-62059082a837/go.mod h1:e2YBjSblNVoBckkbv3PPqsq71q98oFkFqL7s1etViGo=
Expand All @@ -22,6 +24,7 @@ github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03/go.mod
github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ=
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0 h1:rVVNq0x6RGQIzCo1iiJlGFm9AGIZzeifggxtKMU7zmI=
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBwFmYdT8SOFUwB3ovSUfG1Ux0g=
github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20/go.mod h1:mPn+LRRd5gEKNAtc+r3ScpW2JRU/pj4NBKdADYWHiak=
github.com/filecoin-project/go-state-types v0.0.0-20200903145444-247639ffa6ad/go.mod h1:IQ0MBPnonv35CJHtWSN3YY1Hz2gkPru1Q9qoaYLxx9I=
Expand Down
23 changes: 22 additions & 1 deletion telefil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin/v12/market"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/multiformats/go-multiaddr"
"github.com/ybbus/jsonrpc/v3"
Expand All @@ -19,14 +20,15 @@ const (
methodFilStateDealProviderCollateralBounds = `Filecoin.StateDealProviderCollateralBounds`
methodFilStateListMiners = `Filecoin.StateListMiners`
methodFilStateMinerPower = `Filecoin.StateMinerPower`
methodFilStateMarketStorageDeal = `Filecoin.StateMarketStorageDeal`
)

type (
Telefil struct {
client jsonrpc.RPCClient
}
ChainHead struct {
Height int64 `json:"Height"`
Height abi.ChainEpoch `json:"Height"`
}
ChainGenesis struct {
Blocks []struct {
Expand All @@ -46,6 +48,10 @@ type (
QualityAdjPower big.Int `json:"QualityAdjPower"`
RawBytePower big.Int `json:"RawBytePower"`
}
StateMarketStorageDeal struct {
Proposal market.DealProposal `json:"Proposal"`
State market.DealState `json:"State"`
}
)

func New(o ...Option) (*Telefil, error) {
Expand Down Expand Up @@ -174,3 +180,18 @@ func (f *Telefil) StateListMiners(ctx context.Context) ([]address.Address, error
return mids, nil
}
}

func (f *Telefil) StateMarketStorageDeal(ctx context.Context, id abi.DealID) (*StateMarketStorageDeal, error) {
switch resp, err := f.client.Call(ctx, methodFilStateMarketStorageDeal, id, nil); {
case err != nil:
return nil, err
case resp.Error != nil:
return nil, resp.Error
default:
var deal StateMarketStorageDeal
if err = resp.GetObject(&deal); err != nil {
return nil, err
}
return &deal, nil
}
}

0 comments on commit 37d0451

Please sign in to comment.