| @@ -1105,6 +1105,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository) (err error | |||||
| Type: tp, | Type: tp, | ||||
| Config: &CloudBrainConfig{EnableCloudBrain: true}, | Config: &CloudBrainConfig{EnableCloudBrain: true}, | ||||
| }) | }) | ||||
| } else if tp == UnitTypeBlockChain { | |||||
| units = append(units, RepoUnit{ | |||||
| RepoID: repo.ID, | |||||
| Type: tp, | |||||
| Config: &BlockChainConfig{EnableBlockChain: true}, | |||||
| }) | |||||
| } else { | } else { | ||||
| units = append(units, RepoUnit{ | units = append(units, RepoUnit{ | ||||
| RepoID: repo.ID, | RepoID: repo.ID, | ||||
| @@ -141,6 +141,20 @@ func (cfg *CloudBrainConfig) ToDB() ([]byte, error) { | |||||
| return json.Marshal(cfg) | return json.Marshal(cfg) | ||||
| } | } | ||||
| type BlockChainConfig struct { | |||||
| EnableBlockChain bool | |||||
| } | |||||
| // FromDB fills up a CloudBrainConfig from serialized format. | |||||
| func (cfg *BlockChainConfig) FromDB(bs []byte) error { | |||||
| return json.Unmarshal(bs, &cfg) | |||||
| } | |||||
| // ToDB exports a CloudBrainConfig to a serialized format. | |||||
| func (cfg *BlockChainConfig) ToDB() ([]byte, error) { | |||||
| return json.Marshal(cfg) | |||||
| } | |||||
| // BeforeSet is invoked from XORM before setting the value of a field of this object. | // BeforeSet is invoked from XORM before setting the value of a field of this object. | ||||
| func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { | func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { | ||||
| switch colName { | switch colName { | ||||
| @@ -160,6 +174,8 @@ func (r *RepoUnit) BeforeSet(colName string, val xorm.Cell) { | |||||
| r.Config = new(DatasetConfig) | r.Config = new(DatasetConfig) | ||||
| case UnitTypeCloudBrain: | case UnitTypeCloudBrain: | ||||
| r.Config = new(CloudBrainConfig) | r.Config = new(CloudBrainConfig) | ||||
| case UnitTypeBlockChain: | |||||
| r.Config = new(BlockChainConfig) | |||||
| default: | default: | ||||
| panic("unrecognized repo unit type: " + com.ToStr(*val)) | panic("unrecognized repo unit type: " + com.ToStr(*val)) | ||||
| } | } | ||||
| @@ -33,7 +33,7 @@ func MustEnableBlockChain(ctx *context.Context) { | |||||
| } | } | ||||
| func BlockChainIndex(ctx *context.Context) { | func BlockChainIndex(ctx *context.Context) { | ||||
| MustEnableBlockChain(ctx) | |||||
| //MustEnableBlockChain(ctx) | |||||
| repo := ctx.Repo.Repository | repo := ctx.Repo.Repository | ||||
| if repo.ContractAddress == "" || ctx.User.PublicKey == ""{ | if repo.ContractAddress == "" || ctx.User.PublicKey == ""{ | ||||
| log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID) | log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID) | ||||
| @@ -145,11 +145,9 @@ | |||||
| </a> | </a> | ||||
| {{end}} | {{end}} | ||||
| {{if .Permission.CanRead $.UnitTypeBlockChain}} | |||||
| <a class="activate item" href="{{.RepoLink}}/blockchain"> | <a class="activate item" href="{{.RepoLink}}/blockchain"> | ||||
| <i class="balance scale icon"></i> {{.i18n.Tr "repo.balance"}} | <i class="balance scale icon"></i> {{.i18n.Tr "repo.balance"}} | ||||
| </a> | </a> | ||||
| {{end}} | |||||
| {{template "custom/extra_tabs" .}} | {{template "custom/extra_tabs" .}} | ||||