-
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-1614] Provisional bootstrapper to templates
https://jira.hyperledger.org/browse/FAB-1614 This changeset converts the orderer provisional bootstrapper to use the new configtx.Template mechanism. This is a precursor to removing the duplicate genesis code from protos/utils. Change-Id: I47ca9a9c8bcfab2b4eeff5b40b84da71a0230a08 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
- Loading branch information
Jason Yellick
committed
Jan 13, 2017
1 parent
47c182f
commit c53d2e0
Showing
5 changed files
with
150 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
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 genesis | ||
|
||
import ( | ||
"github.com/hyperledger/fabric/common/configtx" | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
"github.com/hyperledger/fabric/protos/utils" | ||
) | ||
|
||
const ( | ||
msgVersion = int32(1) | ||
|
||
// These values are fixed for the genesis block. | ||
lastModified = 0 | ||
epoch = 0 | ||
) | ||
|
||
type Factory interface { | ||
Block(chainID string) (*cb.Block, error) | ||
} | ||
|
||
type factory struct { | ||
template configtx.Template | ||
} | ||
|
||
func NewFactoryImpl(template configtx.Template) Factory { | ||
return &factory{template: template} | ||
} | ||
|
||
func (f *factory) Block(chainID string) (*cb.Block, error) { | ||
items, err := f.template.Items(chainID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
payloadChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_TRANSACTION, msgVersion, chainID, epoch) | ||
payloadSignatureHeader := utils.MakeSignatureHeader(nil, utils.CreateNonceOrPanic()) | ||
payloadHeader := utils.MakePayloadHeader(payloadChainHeader, payloadSignatureHeader) | ||
payload := &cb.Payload{Header: payloadHeader, Data: utils.MarshalOrPanic(&cb.ConfigurationEnvelope{Items: items})} | ||
envelope := &cb.Envelope{Payload: utils.MarshalOrPanic(payload), Signature: nil} | ||
|
||
block := cb.NewBlock(0, nil) | ||
block.Data = &cb.BlockData{Data: [][]byte{utils.MarshalOrPanic(envelope)}} | ||
block.Header.DataHash = block.Data.Hash() | ||
block.Metadata.Metadata[cb.BlockMetadataIndex_LAST_CONFIGURATION] = utils.MarshalOrPanic(&cb.Metadata{ | ||
Value: utils.MarshalOrPanic(&cb.LastConfiguration{Index: 0}), | ||
}) | ||
return block, nil | ||
} |
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,32 @@ | ||
/* | ||
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 genesis | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric/common/configtx" | ||
cb "github.com/hyperledger/fabric/protos/common" | ||
) | ||
|
||
func TestSanity(t *testing.T) { | ||
impl := NewFactoryImpl(configtx.NewSimpleTemplate(&cb.ConfigurationItem{})) | ||
_, err := impl.Block("TestChainID") | ||
if err != nil { | ||
t.Fatalf("Basic sanity fails") | ||
} | ||
} |
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