wallet

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2021 License: Apache-2.0, MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InAppWallet = "BTFS Wallet"
	BttWallet   = "BTT Wallet"

	StatusPending = "Pending"
	StatusSuccess = "Success"
	StatusFailed  = "Failed"
)

Variables

View Source
var (
	ErrTransactionParam   = errors.New("transaction is nil")
	ErrChannelStateParam  = errors.New("channelState is nil")
	ErrChannelCommitParam = errors.New("channelCommit is nil")
	ErrTypeParam          = errors.New("wrong type")
)
View Source
var (
	ErrInsufficientExchangeBalanceOnTron   = errors.New("exchange balance on Tron network is not sufficient")
	ErrInsufficientUserBalanceOnTron       = errors.New(fmt.Sprint("User balance on tron network is not sufficient."))
	ErrInsufficientUserBalanceOnLedger     = errors.New("rpc error: code = ResourceExhausted desc = NSF")
	ErrInsufficientExchangeBalanceOnLedger = errors.New("exchange balance on Private Ledger is not sufficient")
)
View Source
var (
	WithdrawMinAmount int64 = 1
	WithdrawMaxAmount int64 = 1000000000000
	DepositMinAmount  int64 = 1
	DepositMaxAmount  int64 = 1000000000000
	TokenId                 = "1002000"
	TokenIdDev              = "1000252"
)

Functions

func Balance

func Balance(ctx context.Context, configuration *config.Config) (int64, error)

func BalanceHelper

func BalanceHelper(ctx context.Context, configuration *config.Config, offsign bool, signedBytes []byte, lgSignedPubKey *ledgerpb.SignedPublicKey) (int64, error)

func ConfirmDeposit

func ConfirmDeposit(ctx context.Context, logId int64) (*exPb.ConfirmDepositResponse, error)

Call exchange's ConfirmDeposit API.

func ConfirmDepositProcess

func ConfirmDepositProcess(ctx context.Context, n *core.IpfsNode, prepareResponse *exPb.PrepareDepositResponse,
	privateKey *ecdsa.PrivateKey) error

Continuous call ConfirmDeposit until it responses a FAILED or SUCCESS.

func DecryptWithAES

func DecryptWithAES(key, message string) (string, error)

func Deposit

func Deposit(ctx context.Context, n *core.IpfsNode, ledgerAddr []byte, amount int64,
	privateKey *ecdsa.PrivateKey, runDaemon bool, async bool) (*exPb.PrepareDepositResponse, error)

Do the deposit action, integrate exchange's PrepareDeposit and Deposit API.

func DepositRequest

func DepositRequest(ctx context.Context, prepareResponse *exPb.PrepareDepositResponse, privateKey *ecdsa.PrivateKey) (*exPb.DepositResponse, error)

Call exchange's Deposit API

func DiscoverySpeedKey

func DiscoverySpeedKey(password string) (string, error)

return speed key in base64

func EncryptWithAES

func EncryptWithAES(key, message string) (string, error)

func GetBalance

func GetBalance(ctx context.Context, configuration *config.Config) (int64, int64, error)

GetBalance both on ledger and Tron.

func GetBalanceByWalletAddress

func GetBalanceByWalletAddress(ctx context.Context, solidityUrl string, walletAddress string) (tokenMap map[string]int64, err error)

func GetStatus

func GetStatus(ctx context.Context, url string, txId string) (string, error)

func GetTokenBalance

func GetTokenBalance(ctx context.Context, addr []byte, tokenId string) (int64, error)

Get the token balance on tron blockchain

func GetTransactions

func GetTransactions(d ds.Datastore, peerId string) ([]*walletpb.TransactionV1, error)

func Init

func Init(ctx context.Context, configuration *config.Config) error

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) ([]byte, error)

func PKCS5Unpadding

func PKCS5Unpadding(encrypt []byte) ([]byte, error)

func PersistTx

func PersistTx(d ds.Datastore, peerId string, txId string, amount int64,
	from string, to string, status string, txType walletpb.TransactionV1_Type) error

func PersistTxWithTime

func PersistTxWithTime(d ds.Datastore, peerId string, txId string, amount int64,
	from string, to string, status string, txType walletpb.TransactionV1_Type, timeCreate time.Time) error

func PrepareDeposit

func PrepareDeposit(ctx context.Context, ledgerAddr []byte, amount int64) (*exPb.PrepareDepositResponse, error)

Call exchange's PrepareDeposit API.

func PrepareTx

func PrepareTx(ctx context.Context, cfg *config.Config, from string, to string, amount int64, memo string) (*tronPb.TransactionExtention, error)

func PrepareWithdraw

func PrepareWithdraw(ctx context.Context, ledgerAddr, externalAddr []byte, amount, outTxId int64) (
	*exPb.PrepareWithdrawResponse, error)

Call exchange's Withdraw API

func SendRawTransaction

func SendRawTransaction(ctx context.Context, url string, raw []byte, sig []byte) error

func SetKeys

func SetKeys(n *core.IpfsNode, privKey string, mnemonic string) (err error)

func Sign

func Sign(in interface{}, key *ecdsa.PrivateKey) ([]byte, error)

Sign a Transaction, ChannelState, ChannelCommit in exchange proto or tron proto or ledger proto. parameter 'in' can be Transaction, ChannelState, ChannelCommit, return signature.

func SignChannel

func SignChannel(raw []byte, key *ecdsa.PrivateKey) ([]byte, error)

Channel' sign function, return signature and error.

func SignTron

func SignTron(rawData []byte, key *ecdsa.PrivateKey) ([]byte, error)

Tron' Sign function, return signature and error.

func UpdatePendingTransactions

func UpdatePendingTransactions(ctx context.Context, d ds.Datastore, cfg *config.Config, peerId string) (int, int, error)

func UpdateStatus

func UpdateStatus(d ds.Datastore, peerId string, txId string, status string) error

func WalletDeposit

func WalletDeposit(ctx context.Context, configuration *config.Config, n *core.IpfsNode,
	amount int64, runDaemon bool, async bool) error

func WalletWithdraw

func WalletWithdraw(ctx context.Context, configuration *config.Config, n *core.IpfsNode, amount int64) error

withdraw from ledger to tron

func Withdraw

func Withdraw(ctx context.Context, n *core.IpfsNode, ledgerAddr, externalAddr []byte, amount int64,
	privateKey *ecdsa.PrivateKey) (int64, int64, error)

Do the withdraw action, integrate exchange's PrepareWithdraw and Withdraw API, return channel id and error. If Withdraw succeed, with return channel id and logInfo id, error is nil; otherwise will return error, channel id and logInfo id is 0.

func WithdrawRequest

func WithdrawRequest(ctx context.Context, channelId *ledgerPb.ChannelID, ledgerAddr []byte, amount int64,
	prepareResponse *exPb.PrepareWithdrawResponse, privateKey *ecdsa.PrivateKey) (*exPb.WithdrawResponse, error)

Call exchange's PrepareWithdraw API

Types

type EcdsaSignature

type EcdsaSignature struct {
	R, S *big.Int
}

type TronRet

type TronRet struct {
	Message string
	Result  bool
	Code    string
	TxId    string
}

func TransferBTT

func TransferBTT(ctx context.Context, n *core.IpfsNode, cfg *config.Config, privKey ic.PrivKey,
	from string, to string, amount int64) (*TronRet, error)

func TransferBTTWithMemo

func TransferBTTWithMemo(ctx context.Context, n *core.IpfsNode, cfg *config.Config, privKey ic.PrivKey,
	from string, to string, amount int64, memo string) (*TronRet, error)

type TxData

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

func SyncTxFromTronGrid

func SyncTxFromTronGrid(ctx context.Context, cfg *config.Config, ds datastore.Datastore) ([]*TxData, error)

type TxSlice

type TxSlice []*walletpb.TransactionV1

func (TxSlice) Len

func (p TxSlice) Len() int

func (TxSlice) Less

func (p TxSlice) Less(i, j int) bool

func (TxSlice) Swap

func (p TxSlice) Swap(i, j int)

type Wallet

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

Jump to

Keyboard shortcuts

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