Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix new user and guest #2050

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"net/http"
"strings"
"time"

"github.com/IBAX-io/go-ibax/packages/common/crypto"
Expand Down Expand Up @@ -198,15 +197,15 @@ func (m Mode) loginHandler(w http.ResponseWriter, r *http.Request) {

if !conf.Config.IsSupportingCLB() {
gt := 3 * syspar.GetMaxBlockGenerationTime()
his := &sqldb.History{}
l := &sqldb.LogTransaction{}
for i := 0; i < 2; i++ {
found, err := his.Get(stp.Hash)
found, err := l.GetByHash(stp.Hash)
if err != nil {
errorResponse(w, err)
return
}
if found && his.BlockID > 0 {
if strings.Contains(his.Comment, "(error)") {
if found {
if l.Status != 0 {
errorResponse(w, errors.New(`encountered some problems when login account`))
return
} else {
Expand All @@ -217,7 +216,7 @@ func (m Mode) loginHandler(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Duration(gt) * time.Millisecond)
}

if his.BlockID == 0 {
if l.Block == 0 {
errorResponse(w, errNewUser)
return
}
Expand Down Expand Up @@ -261,7 +260,7 @@ func (m Mode) loginHandler(w http.ResponseWriter, r *http.Request) {

verify, err := crypto.Verify(publicKey, []byte(nonceSalt()+uid), form.Signature.Bytes())
if err != nil {
logger.WithFields(log.Fields{"type": consts.CryptoError, "pubkey": publicKey, "uid": uid, "signature": form.Signature.Bytes()}).Error("checking signature")
logger.WithFields(log.Fields{"type": consts.CryptoError, "pubkey": publicKey, "uid": uid, "signature": form.Signature.Bytes()}).Info("checking signature")
errorResponse(w, err)
return
}
Expand Down
6 changes: 3 additions & 3 deletions packages/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ const (
ContractList = 200

// Guest key
GuestPublic = "489347a1205c818d9a02f285faaedd0122a56138e3d985f5e1b4f6a9470f90f692a00a3453771dd7feea388ceb7aefeaf183e299c70ad1aecb7f870bfada3b86"
GuestKey = "4544233900443112470"
GuestAddress = "0454-4233-9004-4311-2470"
GuestPublic = "ef0ab117793962b7b3ee8d2ae94b58bbd7db1aa856a7dc623fdb28ad530090b0bcf5cb81b4d6912a249f1ab30921f414ad88383208cd8ba26ae2a9c3eb543772"
GuestKey = "-110277540701013350"
GuestAddress = "1833-6466-5330-0853-8266"

// StatusMainPage is a status for Main Page
StatusMainPage = `2`
Expand Down
105 changes: 81 additions & 24 deletions packages/migration/contracts/first_ecosystem/NewUser.sim
Original file line number Diff line number Diff line change
@@ -1,29 +1,86 @@
// +prop AppID = '1'
// +prop Conditions = 'ContractConditions("NodeOwnerCondition")'
contract NewUser {
data {
NewPubkey string
}
conditions {
$id = PubToID($NewPubkey)
if $id == 0 {
error "Wrong pubkey"
}
if DBFind("keys").Columns("id").WhereId($id).One("id") {
error "User already exists"
}
}
action {
$pub = HexToPub($NewPubkey)
$account = IdToAddress($id)
$amount = Money(0)
data {
NewPubkey string "optional"
Ecosystem int "optional"
}
func getEcosystem() {
$e_id = Int($Ecosystem)
if $e_id == 0 {
$e_id = $ecosystem_id
}
$eco = DBFind("@1ecosystems").Where({"id": $e_id}).Row()
if !$eco {
warning Sprintf(LangRes("@1ecosystem_not_found"), $e_id)
}
}
func canOpt() bool {
return $free_membership == 1 || $e_id == 1
}
conditions {
getEcosystem()
$newId = PubToID($NewPubkey)

DBInsert("keys", {
"id": $id,
"account": $account,
"pub": $pub,
"amount": $amount,
"ecosystem": 1
})
}
if $newId == 0 {
warning LangRes("@1wrong_pub")
}
if Size($NewPubkey) == 0 {
warning "You did not enter the public key"
}
$pub = HexToPub($NewPubkey)
$account = IdToAddress($newId)

$k = DBFind("@1keys").Where({"id": $newId, "account": $account, "ecosystem": $e_id}).Row()

$free_membership = Int(DBFind("@1parameters").Where({"ecosystem": $e_id, "name": "free_membership"}).One("value"))
}

action {
var iscan bool
iscan = canOpt()
if !iscan {
warning Sprintf(LangRes("@1eco_no_open_new_user"), $eco["name"], $e_id)
}
if $k {
var kid int kpub string
kid = Int($k["id"])
kpub = $k["pub"]
if Size(kpub) != 0 {
warning Sprintf(LangRes("@1template_user_exists"), IdToAddress($newId))
}
DBUpdateExt("@1keys", {"id": kid, "ecosystem": $e_id}, {"pub": $pub})
$result = $account
}else{
DBInsert("@1keys", {"id": $newId, "account": $account, "pub": $pub, "ecosystem": $e_id})
if !DBFind("@1keys").Where({"ecosystem": 1, "account": $account}).Row() {
DBInsert("@1keys", {"id": $newId, "account": $account, "pub": $pub, "ecosystem": 1})
var h map
$whiteHoleBalance = DBFind("@1keys").Where({"account": $white_hole_account,"ecosystem":1}).Columns("amount").One("amount")
h["sender_id"] =$white_hole_key
h["sender_balance"] = $whiteHoleBalance
h["recipient_id"] = $newId
h["comment"] = "New User"
h["block_id"] = $block
h["txhash"] = $txhash
h["ecosystem"] = 1
h["type"] = 4
h["created_at"] = $time
DBInsert("@1history", h)
}
$result = $account
}
var h map
$whiteHoleBalance = DBFind("@1keys").Where({"account": $white_hole_account,"ecosystem":$ecosystem_id}).Columns("amount").One("amount")
h["sender_id"] =$white_hole_key
h["sender_balance"] = $whiteHoleBalance
h["recipient_id"] = $newId
h["comment"] = "New User"
h["block_id"] = $block
h["txhash"] = $txhash
h["ecosystem"] = $ecosystem_id
h["type"] = 4
h["created_at"] = $time
DBInsert("@1history", h)
}
}
107 changes: 82 additions & 25 deletions packages/migration/first_ecosys_contracts_data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.