-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec.go
executable file
·56 lines (50 loc) · 1.96 KB
/
exec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package executor
import (
"github.com/bnchain/bnchain/common/address"
drivers "github.com/bnchain/bnchain/system/dapp"
"github.com/bnchain/bnchain/types"
pty "github.com/bnchain/plugin/plugin/dapp/hashlock/types"
)
// Exec_Hlock Action
func (h *Hashlock) Exec_Hlock(hlock *pty.HashlockLock, tx *types.Transaction, index int) (*types.Receipt, error) {
clog.Debug("hashlocklock action")
if hlock.Amount <= 0 {
clog.Warn("hashlock amount <=0")
return nil, pty.ErrHashlockAmount
}
if err := address.CheckAddress(hlock.ToAddress); err != nil {
clog.Warn("hashlock checkaddress")
return nil, err
}
if err := address.CheckAddress(hlock.ReturnAddress); err != nil {
clog.Warn("hashlock checkaddress")
return nil, err
}
if hlock.ReturnAddress != tx.From() {
clog.Warn("hashlock return address")
return nil, pty.ErrHashlockReturnAddrss
}
if hlock.Time <= minLockTime {
clog.Warn("exec hashlock time not enough")
return nil, pty.ErrHashlockTime
}
actiondb := NewAction(h, tx, drivers.ExecAddress(string(tx.Execer)))
return actiondb.Hashlocklock(hlock)
}
// Exec_Hsend Action
func (h *Hashlock) Exec_Hsend(transfer *pty.HashlockSend, tx *types.Transaction, index int) (*types.Receipt, error) {
//unlock 有两个条件: 1. 时间已经过期 2. 密码是对的,返回原来的账户
clog.Debug("hashlockunlock action")
actiondb := NewAction(h, tx, drivers.ExecAddress(string(tx.Execer)))
return actiondb.Hashlocksend(transfer)
}
// Exec_Hunlock Action
func (h *Hashlock) Exec_Hunlock(transfer *pty.HashlockUnlock, tx *types.Transaction, index int) (*types.Receipt, error) {
//send 有两个条件:1. 时间没有过期 2. 密码是对的,币转移到 ToAddress
clog.Debug("hashlocksend action")
actiondb := NewAction(h, tx, drivers.ExecAddress(string(tx.Execer)))
return actiondb.Hashlockunlock(transfer)
}