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