Use MpoolPushMessage

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-07-22 20:02:29 +02:00
parent 46b7546d51
commit dc35f2f40c
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
3 changed files with 11 additions and 50 deletions

View File

@ -125,7 +125,7 @@ func TestPaymentChannels(t *testing.T, b APIBuilder, blocktime time.Duration) {
t.Fatal(err)
}
res = waitForMessage(ctx, t, paymentCreator, settleMsgCid, time.Second, "settle")
res = waitForMessage(ctx, t, paymentCreator, settleMsgCid, time.Second*10, "settle")
if res.Receipt.ExitCode != 0 {
t.Fatal("Unable to settle payment channel")
}

View File

@ -114,32 +114,18 @@ func (a *PaychAPI) PaychSettle(ctx context.Context, addr address.Address) (cid.C
return cid.Undef, err
}
nonce, err := a.MpoolGetNonce(ctx, ci.Control)
if err != nil {
return cid.Undef, err
}
msg := &types.Message{
To: addr,
From: ci.Control,
Value: types.NewInt(0),
Method: builtin.MethodsPaych.Settle,
Nonce: nonce,
GasLimit: 0,
GasPrice: types.NewInt(0),
}
smgs, err := a.MpoolPushMessage(ctx, msg)
smsg, err := a.WalletSignMessage(ctx, ci.Control, msg)
if err != nil {
return cid.Undef, err
}
if _, err := a.MpoolPush(ctx, smsg); err != nil {
return cid.Undef, err
}
return smsg.Cid(), nil
return smgs.Cid(), nil
}
func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid.Cid, error) {
@ -149,31 +135,18 @@ func (a *PaychAPI) PaychCollect(ctx context.Context, addr address.Address) (cid.
return cid.Undef, err
}
nonce, err := a.MpoolGetNonce(ctx, ci.Control)
if err != nil {
return cid.Undef, err
}
msg := &types.Message{
To: addr,
From: ci.Control,
Value: types.NewInt(0),
Method: builtin.MethodsPaych.Collect,
Nonce: nonce,
GasLimit: 0,
GasPrice: types.NewInt(0),
}
smsg, err := a.WalletSignMessage(ctx, ci.Control, msg)
smsg, err := a.MpoolPushMessage(ctx, msg)
if err != nil {
return cid.Undef, err
}
if _, err := a.MpoolPush(ctx, smsg); err != nil {
return cid.Undef, err
}
return smsg.Cid(), nil
}
@ -253,11 +226,6 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s
return cid.Undef, err
}
nonce, err := a.MpoolGetNonce(ctx, ci.Control)
if err != nil {
return cid.Undef, err
}
if sv.Extra != nil || len(sv.SecretPreimage) > 0 {
return cid.Undef, fmt.Errorf("cant handle more advanced payment channel stuff yet")
}
@ -270,25 +238,17 @@ func (a *PaychAPI) PaychVoucherSubmit(ctx context.Context, ch address.Address, s
}
msg := &types.Message{
From: ci.Control,
To: ch,
Value: types.NewInt(0),
Nonce: nonce,
Method: builtin.MethodsPaych.UpdateChannelState,
Params: enc,
GasLimit: 0,
GasPrice: types.NewInt(0),
From: ci.Control,
To: ch,
Value: types.NewInt(0),
Method: builtin.MethodsPaych.UpdateChannelState,
Params: enc,
}
smsg, err := a.WalletSignMessage(ctx, ci.Control, msg)
smsg, err := a.MpoolPushMessage(ctx, msg)
if err != nil {
return cid.Undef, err
}
if _, err := a.MpoolPush(ctx, smsg); err != nil {
return cid.Undef, err
}
// TODO: should we wait for it...?
return smsg.Cid(), nil
}

View File

@ -552,6 +552,7 @@ func TestPaymentChannels(t *testing.T) {
logging.SetLogLevel("chainstore", "ERROR")
logging.SetLogLevel("chain", "ERROR")
logging.SetLogLevel("sub", "ERROR")
logging.SetLogLevel("pubsub", "ERROR")
logging.SetLogLevel("storageminer", "ERROR")
test.TestPaymentChannels(t, mockSbBuilder, 5*time.Millisecond)