mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Fix chaincode/abstore, add parameter judgment when the transaction makes payment. (#825)
Signed-off-by: yjwxfq <yjwxfq@163.com> Signed-off-by: yjwxfq <yjwxfq@163.com>
This commit is contained in:
parent
0aa853e0c3
commit
6b989299e0
1 changed files with 6 additions and 0 deletions
|
|
@ -50,6 +50,9 @@ func (t *ABstore) Init(ctx contractapi.TransactionContextInterface, A string, Av
|
||||||
|
|
||||||
// Transaction makes payment of X units from A to B
|
// Transaction makes payment of X units from A to B
|
||||||
func (t *ABstore) Invoke(ctx contractapi.TransactionContextInterface, A, B string, X int) error {
|
func (t *ABstore) Invoke(ctx contractapi.TransactionContextInterface, A, B string, X int) error {
|
||||||
|
if X < 0 {
|
||||||
|
return fmt.Errorf("X input is wrong, it should be greater than 0")
|
||||||
|
}
|
||||||
var err error
|
var err error
|
||||||
var Aval int
|
var Aval int
|
||||||
var Bval int
|
var Bval int
|
||||||
|
|
@ -63,6 +66,9 @@ func (t *ABstore) Invoke(ctx contractapi.TransactionContextInterface, A, B strin
|
||||||
return fmt.Errorf("Entity not found")
|
return fmt.Errorf("Entity not found")
|
||||||
}
|
}
|
||||||
Aval, _ = strconv.Atoi(string(Avalbytes))
|
Aval, _ = strconv.Atoi(string(Avalbytes))
|
||||||
|
if Aval < X {
|
||||||
|
return fmt.Errorf("The value of A is not enough to make the payment.")
|
||||||
|
}
|
||||||
|
|
||||||
Bvalbytes, err := ctx.GetStub().GetState(B)
|
Bvalbytes, err := ctx.GetStub().GetState(B)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue