fil

package
v0.0.0-...-7fbff23 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInsuffientFunds = errors.New("insufficient funds")

ErrInsuffientFunds is an error that should be returned by WalletBackend.Send method if the address does not have enough funds.

Functions

func AttoFILToFIL

func AttoFILToFIL(attoFIL *big.Int) float64

AttoFILtoFIL converts a big.Int containing the attoFIL base unit to a float of the amount of Filecoin.

func FILtoAttoFIL

func FILtoAttoFIL(fil float64) *big.Int

FILtoAttoFIL converts a float containing an amount of Filecoin to a big.Int representation in the attoFil base unit.

Types

type FilecoinBackend

type FilecoinBackend interface {
	// Store will put a file to Filecoin and pay for it out of the provided
	// address. A jobID is return or an error.
	Store(data io.Reader, addr addr.Address, userToken string) (jobID, contentID string, size int64, err error)

	JobStatus(cid string, userToken string) (*userPb.StorageJob, error)

	Get(cid string, userToken string) (io.Reader, error)

	CreateUser() (id string, token string, error error)
}

FilecoinBackend is an interface to a Filecoin backend that interacts with the Filecoin network and handles storage deals and retrieval.

type MockFilecoinBackend

type MockFilecoinBackend struct {
	// contains filtered or unexported fields
}

MockFilecoinBackend is a mock backend for a Filecoin service

func NewMockFilecoinBackend

func NewMockFilecoinBackend(dataDir string, adminToken string) (*MockFilecoinBackend, error)

NewMockFilecoinBackend instantiates a new FilecoinBackend

func (*MockFilecoinBackend) CreateUser

func (f *MockFilecoinBackend) CreateUser() (string, string, error)

func (*MockFilecoinBackend) Get

func (f *MockFilecoinBackend) Get(cid string, userToken string) (io.Reader, error)

func (*MockFilecoinBackend) JobStatus

func (f *MockFilecoinBackend) JobStatus(cid string, userToken string) (*userPb.StorageJob, error)

func (*MockFilecoinBackend) Store

func (f *MockFilecoinBackend) Store(data io.Reader, addr addr.Address, userToken string) (jobID, contentID string, size int64, err error)

Store will put a file to Filecoin and pay for it out of the provided address. A jobID is return or an error.

type MockWalletBackend

type MockWalletBackend struct {
	// contains filtered or unexported fields
}

MockWalletBackend is a mock backend for the wallet that allows for making mock transactions and generating mock blocks.

func NewMockWalletBackend

func NewMockWalletBackend() *MockWalletBackend

NewMockWalletBackend instantiates a new WalletBackend.

func (*MockWalletBackend) Balance

func (w *MockWalletBackend) Balance(addr string, userToken string) (*big.Int, error)

Balance returns the balance for an address.

func (*MockWalletBackend) GenerateToAddress

func (w *MockWalletBackend) GenerateToAddress(addr string, amount *big.Int)

GenerateToAddress creates mock coins and sends them to the address.

func (*MockWalletBackend) NewAddress

func (w *MockWalletBackend) NewAddress(userToken string) (string, error)

NewAddress generates a new address and store the key in the backend.

func (*MockWalletBackend) Send

func (w *MockWalletBackend) Send(from, to string, amount *big.Int, userToken string) (string, error)

Send filecoin from one address to another. Returns the cid of the transaction.

func (*MockWalletBackend) SetNextAddress

func (w *MockWalletBackend) SetNextAddress(addr addr.Address)

func (*MockWalletBackend) SetNextTime

func (w *MockWalletBackend) SetNextTime(timestamp time.Time)

func (*MockWalletBackend) SetNextTxid

func (w *MockWalletBackend) SetNextTxid(id string)

func (*MockWalletBackend) Transactions

func (w *MockWalletBackend) Transactions(addr string, limit, offset int) ([]Transaction, error)

Transactions returns the list of transactions for an address.

type PowergateBackend

type PowergateBackend struct {
	// contains filtered or unexported fields
}

PowergateBackend is a mock backend for a Filecoin service using Powergate

func NewPowergateBackend

func NewPowergateBackend(dataDir string, adminToken string, hostname string) (*PowergateBackend, error)

NewPowergateBackend instantiates a new FilecoinBackend

func (*PowergateBackend) CreateUser

func (f *PowergateBackend) CreateUser() (string, string, error)

func (*PowergateBackend) Get

func (f *PowergateBackend) Get(cid string, userToken string) (io.Reader, error)

func (*PowergateBackend) JobStatus

func (f *PowergateBackend) JobStatus(cid string, userToken string) (*userPb.StorageJob, error)

func (*PowergateBackend) Store

func (f *PowergateBackend) Store(data io.Reader, addr addr.Address, userToken string) (jobId, contentID string, size int64, err error)

Store will put a file to Filecoin and pay for it out of the provided address. A jobID is return or an error.

type PowergateUser

type PowergateUser struct {
	// contains filtered or unexported fields
}

type PowergateWalletBackend

type PowergateWalletBackend struct {
	// contains filtered or unexported fields
}

MockWalletBackend is a mock backend for the wallet that allows for making mock transactions and generating mock blocks.

func NewPowergateWalletBackend

func NewPowergateWalletBackend(hostname string) (*PowergateWalletBackend, error)

NewMockWalletBackend instantiates a new WalletBackend.

func (*PowergateWalletBackend) Balance

func (w *PowergateWalletBackend) Balance(address string, userToken string) (*big.Int, error)

Balance returns the balance for an address.

func (*PowergateWalletBackend) GenerateToAddress

func (w *PowergateWalletBackend) GenerateToAddress(addr string, amount *big.Int)

GenerateToAddress creates mock coins and sends them to the address.

func (*PowergateWalletBackend) NewAddress

func (w *PowergateWalletBackend) NewAddress(userToken string) (string, error)

NewAddress generates a new address and store the key in the backend.

func (*PowergateWalletBackend) Send

func (w *PowergateWalletBackend) Send(from, to string, amount *big.Int, userToken string) (string, error)

Send filecoin from one address to another. Returns the cid of the transaction.

func (*PowergateWalletBackend) SetNextAddress

func (w *PowergateWalletBackend) SetNextAddress(addr addr.Address)

func (*PowergateWalletBackend) SetNextTime

func (w *PowergateWalletBackend) SetNextTime(timestamp time.Time)

func (*PowergateWalletBackend) SetNextTxid

func (w *PowergateWalletBackend) SetNextTxid(id string)

func (*PowergateWalletBackend) Transactions

func (w *PowergateWalletBackend) Transactions(addr string, limit, offset int) ([]Transaction, error)

Transactions returns the list of transactions for an address.

type Transaction

type Transaction struct {
	ID        string
	From      string
	To        string
	Amount    *big.Int
	Timestamp time.Time
}

Transaction represents a Filecoin transaction.

func (*Transaction) MarshalJSON

func (t *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaller for Transaction.

type WalletBackend

type WalletBackend interface {
	// NewAddress generates a new address and store the key in the backend.
	NewAddress(userToken string) (string, error)

	// Send filecoin from one address to another. Returns the cid of the
	// transaction.
	Send(from, to string, amount *big.Int, userToken string) (string, error)

	// Balance returns the balance for an address.
	Balance(address string, userToken string) (*big.Int, error)

	// Transactions returns the list of transactions for an address.
	Transactions(addr string, limit, offset int) ([]Transaction, error)
}

WalletBackend is an interface for a Filecoin wallet that can hold the keys for multiple addresses and can make transactions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL