diff --git a/api.go b/api.go index 761f99f..899b4d9 100644 --- a/api.go +++ b/api.go @@ -156,22 +156,22 @@ func ReLoadConfigAPIHandler(w http.ResponseWriter, r *http.Request) { } type PublishExtraInfo struct { - MerkleRoot string `json:"mklroot"` - Mode string `json:"mode"` - SubMode string `json:"sub_mode"` - UnitPrice int64 `json:"uprice"` - Description string `json:"description"` - ContractAddr string `json:"contract_addr"` + MerkleRoot string `json:"mklroot"` + Mode string `json:"mode"` + SubMode []string `json:"sub_mode"` + UnitPrice int64 `json:"uprice"` + Description string `json:"description"` + ContractAddr string `json:"contract_addr"` } type InitPublishConfig struct { - Mode string `json:"mode"` - SubMode string `json:"sub_mode"` - Column string `json:"column"` - Keys []int `json:"keys"` - UnitPrice int64 `json:"unit_price"` - Description string `json:"description"` - FilePath string `json:"file_path"` + Mode string `json:"mode"` + SubMode []string `json:"sub_mode"` + Column string `json:"column"` + Keys []int `json:"keys"` + UnitPrice int64 `json:"unit_price"` + Description string `json:"description"` + FilePath string `json:"file_path"` } //InitPublishDataAPIHandler is a api handler for seller to initializing data for publishing. @@ -202,12 +202,29 @@ func InitPublishDataAPIHandler(w http.ResponseWriter, r *http.Request) { return } - if (config.Mode == "plain" && (config.SubMode == "table1" || config.SubMode == "table2") && config.Column != "") || - (config.Mode == "table" && (config.SubMode == "table1" || config.SubMode == "table2" || config.SubMode == "vrf") && len(config.Keys) != 0) { - Log.Warnf("parameters are incomplete. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys) + if len(config.SubMode) == 0 { + Log.Warnf("parameters are incomplete, submode is nil. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys) fmt.Fprintf(w, RESPONSE_INCOMPLETE_PARAM) return } + + if config.Mode == TRANSACTION_MODE_PLAIN_POD { + for _, s := range config.SubMode { + if s != TRANSACTION_SUB_MODE_BATCH1 && s != TRANSACTION_SUB_MODE_BATCH2 { + Log.Warnf("parameters are incomplete. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys) + fmt.Fprintf(w, RESPONSE_INCOMPLETE_PARAM) + return + } + } + } else if config.Mode == TRANSACTION_MODE_TABLE_POD { + for _, s := range config.SubMode { + if s != TRANSACTION_SUB_MODE_BATCH1 && s != TRANSACTION_SUB_MODE_BATCH2 && s != TRANSACTION_SUB_MODE_VRF { + Log.Warnf("parameters are incomplete. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys) + fmt.Fprintf(w, RESPONSE_INCOMPLETE_PARAM) + return + } + } + } Log.Debugf("parameter verified. mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys) plog.Detail = fmt.Sprintf("mode=%v, subMode=%v, column=%v, keys=%v", config.Mode, config.SubMode, config.Column, config.Keys) @@ -621,7 +638,7 @@ func BuyerPurchaseDataAPIHandler(w http.ResponseWriter, r *http.Request) { plog.Detail = fmt.Sprintf("%v, merkle root=%v,", plog.Detail, bulletin.SigmaMKLRoot) Log.Debugf("step0: prepare for transaction...") - var params = BuyerConnParam{data.SellerIP, data.SellerAddr, bulletin.Mode, "", data.OT, data.UnitPrice, "", bulletin.SigmaMKLRoot} + var params = BuyerConnParam{data.SellerIP, data.SellerAddr, bulletin.Mode, data.SubMode, data.OT, data.UnitPrice, "", bulletin.SigmaMKLRoot} node, conn, params, err := preBuyerConn(params, ETHKey, Log) if err != nil { Log.Warnf("failed to prepare net for transaction. err=%v", err) diff --git a/buyer_tx.go b/buyer_tx.go index 3ecfe30..fe7dbb9 100644 --- a/buyer_tx.go +++ b/buyer_tx.go @@ -608,7 +608,7 @@ func buyerTxForPB2(node *pod_net.Node, key *keystore.Key, tx BuyerTransaction, d tx.Status = TRANSACTION_STATUS_VERIFY_FAILED return fmt.Sprintf(RESPONSE_TRANSACTION_FAILED, "step1: failed to purchase data.") } else { - Log.Warnf("[%v]step6: start decrypt data...", tx.SessionID) + Log.Debugf("[%v]step6: start decrypt data...", tx.SessionID) rs = tx.PlainBatch2.buyerDecrypt(outputFile, Log) if !rs { tx.Status = TRANSACTION_STATUS_DECRYPT_FAILED diff --git a/init.go b/init.go index c4f1b13..f7ab2f7 100644 --- a/init.go +++ b/init.go @@ -47,7 +47,7 @@ type RequestData struct { PubPath string `json:"pub_path"` BulletinFile string `json:"bulletin_file"` // Mode string `json:"mode"` - // SubMode string `json:"sub_mode"` + SubMode string `json:"sub_mode"` OT bool `json:"ot"` Demands []Demand `json:"demands"` Phantoms []Phantom `json:"phantoms"` diff --git a/seller_tx.go b/seller_tx.go index 8375804..a5a5e3b 100644 --- a/seller_tx.go +++ b/seller_tx.go @@ -70,9 +70,22 @@ func preSellerTx(mklroot string, re requestExtra, Log ILogger) (SellerConnParam, } params.UnitPrice = re.Price re.Mode = bulletin.Mode - re.SubMode = extra.SubMode + var subMode string + if len(extra.SubMode) == 0 { + return params, re, fmt.Errorf("no subMode") + } + for _, s := range extra.SubMode { + if re.SubMode == s && s != "" { + subMode = s + break + } + } + if subMode == "" { + subMode = extra.SubMode[0] + } + re.SubMode = subMode params.Mode = bulletin.Mode - params.SubMode = extra.SubMode + params.SubMode = subMode if params.SubMode == TRANSACTION_SUB_MODE_BATCH2 { re.Ot = false }