Skip to content

Commit

Permalink
Merge changes I12628628,Ic7d797be
Browse files Browse the repository at this point in the history
* changes:
  Factor out byte concatenation to utils
  Move core/util to common/util
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed Jan 11, 2017
2 parents b8965c9 + 52c92f5 commit e187a93
Show file tree
Hide file tree
Showing 60 changed files with 104 additions and 86 deletions.
2 changes: 1 addition & 1 deletion bddtests/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"
)
Expand Down
2 changes: 1 addition & 1 deletion bddtests/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

"github.com/DATA-DOG/godog"
"github.com/DATA-DOG/godog/gherkin"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
)

// BDDContext represents the current context for the executing scenario. Commensurate concept of 'context' from behave testing.
Expand Down
2 changes: 1 addition & 1 deletion bddtests/context_endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (

"github.com/DATA-DOG/godog"
"github.com/DATA-DOG/godog/gherkin"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/platforms"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
"golang.org/x/net/context"
Expand Down
18 changes: 18 additions & 0 deletions core/util/utils.go → common/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,21 @@ func GetTestOrgID() string {
func GetSysCCVersion() string {
return metadata.Version
}

// ConcatenateBytes is useful for combining multiple arrays of bytes, especially for
// signatures or digests over multiple fields
func ConcatenateBytes(data ...[]byte) []byte {
finalLength := 0
for _, slice := range data {
finalLength += len(slice)
}
result := make([]byte, finalLength)
last := 0
for _, slice := range data {
for i := range slice {
result[i+last] = slice[i]
}
last += len(slice)
}
return result
}
24 changes: 24 additions & 0 deletions core/util/utils_test.go → common/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,27 @@ func TestConcurrencyNotFail(t *testing.T) {
logger.Info("")
}
}

func TestMetadataSignatureBytesNormal(t *testing.T) {
first := []byte("first")
second := []byte("second")
third := []byte("third")

result := ConcatenateBytes(first, second, third)
expected := []byte("firstsecondthird")
if !bytes.Equal(result, expected) {
t.Errorf("Did not concatenate bytes correctly, expected %s, got %s", expected, result)
}
}

func TestMetadataSignatureBytesNil(t *testing.T) {
first := []byte("first")
second := []byte(nil)
third := []byte("third")

result := ConcatenateBytes(first, second, third)
expected := []byte("firstthird")
if !bytes.Equal(result, expected) {
t.Errorf("Did not concatenate bytes correctly, expected %s, got %s", expected, result)
}
}
2 changes: 1 addition & 1 deletion core/chaincode/chaincodeexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sync"
"testing"

"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"

"golang.org/x/net/context"
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (

"path/filepath"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/container/ccintf"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
putils "github.com/hyperledger/fabric/protos/utils"

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"time"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/util"
ccintf "github.com/hyperledger/fabric/core/container/ccintf"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/looplab/fsm"
logging "github.com/op/go-logging"
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/lccc.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import (
"strings"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/op/go-logging"
"golang.org/x/net/context"
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/car/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"io/ioutil"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/car/test/car_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"os"
"testing"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/golang/hash.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/op/go-logging"
"github.com/spf13/viper"

"github.com/hyperledger/fabric/common/util"
ccutil "github.com/hyperledger/fabric/core/chaincode/platforms/util"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/java/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
"strings"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/util"
ccutil "github.com/hyperledger/fabric/core/chaincode/platforms/util"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/java/test/java_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import (
"os"
"testing"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"os"
"path/filepath"

"github.com/hyperledger/fabric/common/util"
cutil "github.com/hyperledger/fabric/core/container/util"
"github.com/hyperledger/fabric/core/util"
"github.com/op/go-logging"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/platforms/util/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
)

// TestHashContentChange changes a random byte in a content and checks for hash change
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/shim/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (

"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/comm"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/op/go-logging"
"github.com/spf13/viper"
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/sysccapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (

"golang.org/x/net/context"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/core/container/inproccontroller"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"

"github.com/op/go-logging"
"github.com/spf13/viper"
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/systemchaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/system_chaincode/samplesyscc"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/spf13/viper"
"golang.org/x/net/context"
Expand Down
2 changes: 1 addition & 1 deletion core/chaincode/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"
"testing"

"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"

"github.com/golang/protobuf/proto"
Expand Down
2 changes: 1 addition & 1 deletion core/committer/txvalidator/txvalidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"testing"

"github.com/golang/protobuf/proto"
util2 "github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/ledger/ledgermgmt"
"github.com/hyperledger/fabric/core/ledger/testutil"
"github.com/hyperledger/fabric/core/ledger/util"
util2 "github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
Expand Down
2 changes: 1 addition & 1 deletion core/committer/txvalidator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"fmt"

"github.com/golang/protobuf/proto"
coreUtil "github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/ledger"
ledgerUtil "github.com/hyperledger/fabric/core/ledger/util"
"github.com/hyperledger/fabric/core/peer"
coreUtil "github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/utils"
"github.com/op/go-logging"
Expand Down
2 changes: 1 addition & 1 deletion core/container/ccintf/ccintf.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package ccintf
import (
"encoding/hex"

"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
pb "github.com/hyperledger/fabric/protos/peer"
"golang.org/x/net/context"
)
Expand Down
2 changes: 1 addition & 1 deletion core/container/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"os"
"testing"

"github.com/hyperledger/fabric/common/util"
cutil "github.com/hyperledger/fabric/core/container/util"
"github.com/hyperledger/fabric/core/util"
pb "github.com/hyperledger/fabric/protos/peer"
"golang.org/x/net/context"
)
Expand Down
2 changes: 1 addition & 1 deletion core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"github.com/op/go-logging"
"golang.org/x/net/context"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric/protos/peer"
Expand Down
2 changes: 1 addition & 1 deletion core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import (
"path/filepath"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/chaincode"
"github.com/hyperledger/fabric/core/container"
"github.com/hyperledger/fabric/core/peer"
"github.com/hyperledger/fabric/core/peer/msp"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/msp"
pb "github.com/hyperledger/fabric/protos/peer"
pbutils "github.com/hyperledger/fabric/protos/utils"
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/kvledger/example/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/ledger"

"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/protos/common"
ptestutils "github.com/hyperledger/fabric/protos/testutils"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package lockbasedtxmgr

import (
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/util"
)

// LockBasedQueryExecutor is a query executor used in `LockBasedTxMgr`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package lockbasedtxmgr
import (
"errors"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwset"
"github.com/hyperledger/fabric/core/util"
)

// LockBasedTxSimulator is a transaction simulator used in `LockBasedTxMgr`
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/testutil/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/protos/common"
ptestutils "github.com/hyperledger/fabric/protos/testutils"
)
Expand Down
2 changes: 1 addition & 1 deletion core/ledger/testutil/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"testing"
"time"

"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
"github.com/op/go-logging"
"github.com/spf13/viper"
)
Expand Down
2 changes: 1 addition & 1 deletion core/peer/fullflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"fmt"
"os"

"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/core/peer/msp"
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/peer"
"github.com/hyperledger/fabric/protos/utils"
Expand Down
2 changes: 1 addition & 1 deletion core/peer/msp/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package mspmgmt

import (
"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/common"
mspprotos "github.com/hyperledger/fabric/protos/msp"
Expand Down
2 changes: 1 addition & 1 deletion core/peer/msp/peermsp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mspmgmt
import (
"testing"

"github.com/hyperledger/fabric/core/util"
"github.com/hyperledger/fabric/common/util"
"github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric/protos/msp/testutils"
)
Expand Down
Loading

0 comments on commit e187a93

Please sign in to comment.