Browse Source

block_chain_amount

tags/v0.1.8
yuyuanshifu 4 years ago
parent
commit
6ce5f7d4bd
5 changed files with 19 additions and 20 deletions
  1. +5
    -9
      models/pull.go
  2. +1
    -1
      modules/auth/repo_form.go
  3. +5
    -2
      modules/timer/timer.go
  4. +2
    -2
      routers/repo/blockchain.go
  5. +6
    -6
      routers/repo/pull.go

+ 5
- 9
models/pull.go View File

@@ -36,15 +36,11 @@ const (
PullRequestStatusError
)

// PullRequestDifficulty defines pull request difficulty
type PullRequestDifficulty int

// Enumerate all the pull request difficulty
const (
PullRequestDifficultyZero PullRequestDifficulty = iota
PullRequestDifficultyOne
PullRequestDifficultyTwo
PullRequestDifficultyMax
PullRequestAmountZero int = 0
PullRequestAmountOne int = 100
PullRequestAmountTwo int = 200
PullRequestAmountMax int = 300
)

// PullRequest represents relation between pull request and repositories.
@@ -79,7 +75,7 @@ type PullRequest struct {

//block_chain
IsTransformed bool `xorm:"INDEX NOT NULL DEFAULT false"`
Difficulty PullRequestDifficulty `xorm:"INDEX NOT NULL DEFAULT 0"`
Amount int `xorm:"INDEX NOT NULL DEFAULT 0"`
}

// MustHeadUserName returns the HeadRepo's username if failed return blank


+ 1
- 1
modules/auth/repo_form.go View File

@@ -369,7 +369,6 @@ type CreateIssueForm struct {
AssigneeID int64
Content string
Files []string
Difficulty int `form:"difficulty"`
}

// Validate validates the fields
@@ -490,6 +489,7 @@ type MergePullRequestForm struct {
MergeTitleField string
MergeMessageField string
ForceMerge *bool `json:"force_merge,omitempty"`
BlockChainAmount int `binding:"Required"`
}

// Validate validates the fields


+ 5
- 2
modules/timer/timer.go View File

@@ -18,8 +18,11 @@ func init() {
specCheckRepoBlockChainSuccess := "*/5 * * * *"
c.AddFunc(specCheckRepoBlockChainSuccess, repo.HandleBlockChainUnSuccessRepos)

specCheckUnTransformedActions := "*/1 * * * *"
c.AddFunc(specCheckUnTransformedActions, repo.HandleBlockChainMergedPulls)
//specCheckUnTransformedActions := "*/1 * * * *"
//c.AddFunc(specCheckUnTransformedActions, repo.HandleBlockChainMergedPulls)

//specCheckUnTransformedActions := "*/1 * * * *"
//c.AddFunc(specCheckUnTransformedActions, repo.HandleUnTransformedActions)

//specCheckBlockChainCommitSuccess := "*/3 * * * *"
//c.AddFunc(specCheckBlockChainCommitSuccess, repo.HandleBlockChainUnSuccessCommits)


+ 2
- 2
routers/repo/blockchain.go View File

@@ -293,7 +293,7 @@ func HandleBlockChainMergedPulls() {
CommitID : pr.MergedCommitID,
ContractAddress : repo.ContractAddress,
Status : models.BlockChainCommitInit,
Amount : int64(pr.Difficulty*100),
Amount : int64(pr.Amount),
UserID : poster.ID,
RepoID : pr.HeadRepoID,
}
@@ -306,7 +306,7 @@ func HandleBlockChainMergedPulls() {
pr.IsTransformed = true
pr.UpdateCols("is_transformed")

_, err = blockchain.Contribute(repo.ContractAddress, poster.PublicKey, pr.MergedCommitID, int64(pr.Difficulty*100))
_, err = blockchain.Contribute(repo.ContractAddress, poster.PublicKey, pr.MergedCommitID, int64(pr.Amount))
if err != nil {
log.Error("blockchain.Contribute(%s) failed:%v", pr.MergedCommitID, err)
}


+ 6
- 6
routers/repo/pull.go View File

@@ -810,6 +810,12 @@ func MergePullRequest(ctx *context.Context, form auth.MergePullRequestForm) {
return
}

if form.BlockChainAmount < int(models.PullRequestAmountZero) || form.BlockChainAmount > int(models.PullRequestAmountMax) {
log.Error("amount set error(0-300)")
ctx.RenderWithErr("amount set error(0-300)", tplIssueView, form)
return
}

if err = pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, models.MergeStyle(form.Do), message); err != nil {
if models.IsErrInvalidMergeStyle(err) {
ctx.Flash.Error(ctx.Tr("repo.pulls.invalid_merge_option"))
@@ -924,11 +930,6 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
return
}

if form.Difficulty > int(models.PullRequestDifficultyMax) || form.Difficulty < int(models.PullRequestDifficultyZero) {
ctx.RenderWithErr(ctx.Tr("the difficulty set error(0-3)"), tplCompareDiff, form)
return
}

pullIssue := &models.Issue{
RepoID: repo.ID,
Title: form.Title,
@@ -947,7 +948,6 @@ func CompareAndPullRequestPost(ctx *context.Context, form auth.CreateIssueForm)
BaseRepo: repo,
MergeBase: prInfo.MergeBase,
Type: models.PullRequestGitea,
Difficulty: models.PullRequestDifficulty(form.Difficulty),
}
// FIXME: check error in the case two people send pull request at almost same time, give nice error prompt
// instead of 500.


Loading…
Cancel
Save