Skip to content

Commit

Permalink
FAST: SendFilecoinFromDefault returns mcid (#2686)
Browse files Browse the repository at this point in the history
  • Loading branch information
travisperson authored May 4, 2019
1 parent 7ec7aa9 commit 8dc4944
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
14 changes: 12 additions & 2 deletions tools/fast/series/send_filecoin_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ import (
)

// SendFilecoinDefaults sends the `value` amount of fil from the default wallet
// address of the `from` node to the `to` node's default wallet.
// address of the `from` node to the `to` node's default wallet, and waits for the
// message to be received by the `to` node.
func SendFilecoinDefaults(ctx context.Context, from, to *fast.Filecoin, value int) error {
var toAddr address.Address
if err := to.ConfigGet(ctx, "wallet.defaultAddress", &toAddr); err != nil {
return err
}

return SendFilecoinFromDefault(ctx, from, toAddr, value)
mcid, err := SendFilecoinFromDefault(ctx, from, toAddr, value)
if err != nil {
return err
}

if _, err := to.MessageWait(ctx, mcid); err != nil {
return err
}

return nil
}
14 changes: 9 additions & 5 deletions tools/fast/series/send_filecoin_from_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,33 @@ import (
"context"
"math/big"

"github.com/ipfs/go-cid"

"github.com/filecoin-project/go-filecoin/address"
"github.com/filecoin-project/go-filecoin/tools/fast"
)

// SendFilecoinFromDefault will send the `value` of FIL from the default wallet
// address, per the config of the `node`, to the provided address `addr` and
// wait for the message to showup on chain.
func SendFilecoinFromDefault(ctx context.Context, node *fast.Filecoin, addr address.Address, value int) error {
// The waiting node is the sender, this does not guarantee that the message has
// been received by the targeted node of addr.
func SendFilecoinFromDefault(ctx context.Context, node *fast.Filecoin, addr address.Address, value int) (cid.Cid, error) {
var walletAddr address.Address
if err := node.ConfigGet(ctx, "wallet.defaultAddress", &walletAddr); err != nil {
return err
return cid.Undef, err
}

mcid, err := node.MessageSend(ctx, addr, "", fast.AOValue(value), fast.AOFromAddr(walletAddr), fast.AOPrice(big.NewFloat(1.0)), fast.AOLimit(300))
if err != nil {
return err
return cid.Undef, err
}

CtxMiningOnce(ctx)

if _, err := node.MessageWait(ctx, mcid); err != nil {
return err
return cid.Undef, err
}

return nil
return mcid, nil
}

0 comments on commit 8dc4944

Please sign in to comment.