mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 01:25:10 +00:00
Compare commits
3 commits
a05ef1d920
...
53108abed1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
53108abed1 | ||
|
|
119d3bc53f | ||
|
|
074c5dc237 |
11 changed files with 68 additions and 48 deletions
4
.github/actions/fsat-setup/action.yaml
vendored
4
.github/actions/fsat-setup/action.yaml
vendored
|
|
@ -12,10 +12,10 @@ inputs:
|
|||
default: v0.50.15
|
||||
fabric-version:
|
||||
description: Version of Hyperledger Fabric
|
||||
default: "2.5.15"
|
||||
default: "2.5.16"
|
||||
ca-version:
|
||||
description: Version of Hyperledger Fabric CA
|
||||
default: "1.5.15"
|
||||
default: "1.5.21"
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
|
|
|
|||
|
|
@ -12,10 +12,10 @@ inputs:
|
|||
default: 25.x
|
||||
fabric-version:
|
||||
description: Version of Hyperledger Fabric
|
||||
default: 2.5.15
|
||||
default: 2.5.16
|
||||
ca-version:
|
||||
description: Version of Hyperledger Fabric CA
|
||||
default: 1.5.15
|
||||
default: 1.5.21
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ jobs:
|
|||
# Note: The default Fabric version for CI is currently the latest LTS (v2.5.x).
|
||||
# To test BFT Orderers, Fabric v3.x is explicitly specified here.
|
||||
with:
|
||||
fabric-version: 3.1.4
|
||||
fabric-version: 3.1.5
|
||||
|
||||
- name: Run Test Network with BFT Orderers
|
||||
working-directory: test-network
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ write_files:
|
|||
# set -o pipefail
|
||||
|
||||
if [ -z $1 ]; then
|
||||
HLF_VERSION=2.5.15
|
||||
HLF_VERSION=2.5.16
|
||||
else
|
||||
HLF_VERSION=$1
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -33,8 +33,8 @@ function context() {
|
|||
export ${name}="${!override_name:-${default_value}}"
|
||||
}
|
||||
|
||||
context FABRIC_VERSION 2.5.15
|
||||
context FABRIC_CA_VERSION 1.5.15
|
||||
context FABRIC_VERSION 2.5.16
|
||||
context FABRIC_CA_VERSION 1.5.21
|
||||
|
||||
context CLUSTER_RUNTIME kind # or k3s for Rancher
|
||||
context CONTAINER_CLI docker # or nerdctl for containerd
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ fabric-ca-client register \
|
|||
--id.name $USERNAME \
|
||||
--id.secret $PASSWORD \
|
||||
--id.type client \
|
||||
--url https://$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN \
|
||||
--url https://$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN:443 \
|
||||
--tls.certfiles $WORKSHOP_CRYPTO/cas/$ORG-ca/tls-cert.pem \
|
||||
--mspdir $WORKSHOP_CRYPTO/enrollments/$ORG/users/rcaadmin/msp
|
||||
|
||||
fabric-ca-client enroll \
|
||||
--url https://$USERNAME:$PASSWORD@$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN \
|
||||
--url https://$USERNAME:$PASSWORD@$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN:443 \
|
||||
--tls.certfiles $WORKSHOP_CRYPTO/cas/$ORG-ca/tls-cert.pem \
|
||||
--mspdir $WORKSHOP_CRYPTO/enrollments/$ORG/users/$USERNAME/msp
|
||||
|
||||
|
|
|
|||
|
|
@ -332,12 +332,12 @@ fabric-ca-client register \
|
|||
--id.name $USERNAME \
|
||||
--id.secret $PASSWORD \
|
||||
--id.type client \
|
||||
--url https://$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN \
|
||||
--url https://$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN:443 \
|
||||
--tls.certfiles $WORKSHOP_CRYPTO/cas/$ORG-ca/tls-cert.pem \
|
||||
--mspdir $WORKSHOP_CRYPTO/enrollments/$ORG/users/rcaadmin/msp
|
||||
|
||||
fabric-ca-client enroll \
|
||||
--url https://$USERNAME:$PASSWORD@$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN \
|
||||
--url https://$USERNAME:$PASSWORD@$WORKSHOP_NAMESPACE-$ORG-ca-ca.$WORKSHOP_INGRESS_DOMAIN:443 \
|
||||
--tls.certfiles $WORKSHOP_CRYPTO/cas/$ORG-ca/tls-cert.pem \
|
||||
--mspdir $WORKSHOP_CRYPTO/enrollments/$ORG/users/$USERNAME/msp
|
||||
|
||||
|
|
|
|||
|
|
@ -39,8 +39,8 @@ First, run the following command to verify that the environment variables are co
|
|||
```shell
|
||||
$ ./network
|
||||
|
||||
Fabric image versions: Peer (3.1.4), CA (1.5.15)
|
||||
Fabric binary versions: Peer (3.1.4), CA (1.5.15)
|
||||
Fabric image versions: Peer (3.1.5), CA (1.5.21)
|
||||
Fabric binary versions: Peer (3.1.5), CA (1.5.21)
|
||||
|
||||
--- Fabric Information
|
||||
Fabric Version : 3.1
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# default image tag, example: "2.5.13". "default" will download the latest. (-i)
|
||||
# default image tag, example: "2.5.16". "default" will download the latest. (-i)
|
||||
IMAGETAG="default"
|
||||
|
||||
# default ca image tag, example: "1.5.15". "default" will download the latest. (-cai)
|
||||
# default ca image tag, example: "1.5.21". "default" will download the latest. (-cai)
|
||||
CA_IMAGETAG="default"
|
||||
|
||||
# Using crpto vs CA. default is cryptogen
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ function printHelp() {
|
|||
println
|
||||
println " Flags:"
|
||||
println " Used with \033[0;32mnetwork.sh prereq\033[0m:"
|
||||
println " -i FabricVersion (default: '2.5.15')"
|
||||
println " -cai Fabric CA Version (default: '1.5.15')"
|
||||
println " -i FabricVersion (default: '2.5.16')"
|
||||
println " -cai Fabric CA Version (default: '1.5.21')"
|
||||
println
|
||||
elif [ "$USAGE" == "up" ]; then
|
||||
println "Usage: "
|
||||
|
|
@ -159,8 +159,8 @@ function printHelp() {
|
|||
println
|
||||
println " Flags:"
|
||||
println " Used with \033[0;32mnetwork.sh prereq\033[0m"
|
||||
println " -i FabricVersion (default: '2.5.15')"
|
||||
println " -cai Fabric CA Version (default: '1.5.15')"
|
||||
println " -i FabricVersion (default: '2.5.16')"
|
||||
println " -cai Fabric CA Version (default: '1.5.21')"
|
||||
println
|
||||
println " Used with \033[0;32mnetwork.sh up\033[0m, \033[0;32mnetwork.sh createChannel\033[0m:"
|
||||
println " -ca - Use Certificate Authorities to generate network crypto material"
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ package chaincode
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/hyperledger/fabric-protos-go/ledger/queryresult"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
|
@ -949,6 +950,8 @@ func removeBalance(ctx contractapi.TransactionContextInterface, sender string, i
|
|||
}
|
||||
defer balanceIterator.Close()
|
||||
|
||||
var deferredDeletions = []func() error{}
|
||||
|
||||
// Iterate over keys that store balances and add them to partialBalance until
|
||||
// either the necessary amount is reached or the keys ended
|
||||
for balanceIterator.HasNext() && partialBalance < neededAmount {
|
||||
|
|
@ -972,40 +975,47 @@ func removeBalance(ctx contractapi.TransactionContextInterface, sender string, i
|
|||
selfRecipientKeyNeedsToBeRemoved = true
|
||||
selfRecipientKey = queryResponse.Key
|
||||
} else {
|
||||
err = ctx.GetStub().DelState(queryResponse.Key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete the state of %v: %v", queryResponse.Key, err)
|
||||
}
|
||||
deferredDeletions = append(deferredDeletions, deferredDelete(ctx, queryResponse))
|
||||
}
|
||||
}
|
||||
|
||||
if partialBalance < neededAmount {
|
||||
return fmt.Errorf("sender has insufficient funds for token %v, needed funds: %v, available fund: %v", tokenId, neededAmount, partialBalance)
|
||||
} else if partialBalance > neededAmount {
|
||||
// Send the remainder back to the sender
|
||||
remainder, err := sub(partialBalance, neededAmount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if selfRecipientKeyNeedsToBeRemoved {
|
||||
// Set balance for the key that has the same address for sender and recipient
|
||||
err = setBalance(ctx, sender, sender, tokenId, remainder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = addBalance(ctx, sender, sender, tokenId, remainder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Delete self recipient key
|
||||
err = ctx.GetStub().DelState(selfRecipientKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete the state of %v: %v", selfRecipientKey, err)
|
||||
// enough token funds have been found to perform the update
|
||||
// now we can delete the token entries to supply updated token balances
|
||||
for _, deleteFn := range deferredDeletions {
|
||||
err := deleteFn()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if partialBalance > neededAmount {
|
||||
// Send the remainder back to the sender
|
||||
remainder, err := sub(partialBalance, neededAmount)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if selfRecipientKeyNeedsToBeRemoved {
|
||||
// Set balance for the key that has the same address for sender and recipient
|
||||
err = setBalance(ctx, sender, sender, tokenId, remainder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err = addBalance(ctx, sender, sender, tokenId, remainder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Delete self recipient key
|
||||
err = ctx.GetStub().DelState(selfRecipientKey)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete the state of %v: %v", selfRecipientKey, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1013,6 +1023,16 @@ func removeBalance(ctx contractapi.TransactionContextInterface, sender string, i
|
|||
return nil
|
||||
}
|
||||
|
||||
func deferredDelete(ctx contractapi.TransactionContextInterface, queryResponse *queryresult.KV) func() error {
|
||||
return func() error {
|
||||
err := ctx.GetStub().DelState(queryResponse.Key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete the state of %v: %v", queryResponse.Key, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func emitTransferSingle(ctx contractapi.TransactionContextInterface, transferSingleEvent TransferSingle) error {
|
||||
transferSingleEventJSON, err := json.Marshal(transferSingleEvent)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue