-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FAB-1200 wrong type assertion on ledger.KV
https://jira.hyperledger.org/browse/FAB-1200 While investing table structures (still in works) found that chaincode handler was asserting the wrong KV type. Also found that an UnmarshallJSON was missing on proto.ChaincodeInput. This function was defined in transaction.go (wrong file for a ChaincodeInput function!) which went away when old Transaction was axed. Interesting that the tests in common_test.go did not catch that. Added explicit tests for Unmarshalling JSON into ChaincodeInput. Change-Id: I3adc92c888efee974c5f537bc911cb0a253d1e01 Signed-off-by: Srinivasan Muralidharan <muralisr@us.ibm.com>
- Loading branch information
Srinivasan Muralidharan
committed
Nov 28, 2016
1 parent
61affa0
commit 1b844c2
Showing
3 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright IBM Corp. 2016 All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package peer | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/hyperledger/fabric/core/util" | ||
) | ||
|
||
type strArgs struct { | ||
Function string | ||
Args []string | ||
} | ||
|
||
// UnmarshalJSON converts the string-based REST/JSON input to | ||
// the []byte-based current ChaincodeInput structure. | ||
func (c *ChaincodeInput) UnmarshalJSON(b []byte) error { | ||
sa := &strArgs{} | ||
err := json.Unmarshal(b, sa) | ||
if err != nil { | ||
return err | ||
} | ||
allArgs := sa.Args | ||
if sa.Function != "" { | ||
allArgs = append([]string{sa.Function}, sa.Args...) | ||
} | ||
c.Args = util.ToChaincodeArgs(allArgs...) | ||
return nil | ||
} |