Skip to content

Commit

Permalink
three minor modifications:
Browse files Browse the repository at this point in the history
1. check Bob's deposit balance at the beginning of a transaction
2. check Bob's deposit balance and undeposit expire date
3. rename the default folder 'key' to 'zkPodParam'
  • Loading branch information
10to4 committed Jul 14, 2019
1 parent 98206a3 commit 520eefa
Show file tree
Hide file tree
Showing 4 changed files with 397 additions and 204 deletions.
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func CloseDataAPIHandler(w http.ResponseWriter, r *http.Request) {
return
}

Log.Debugf("start send transaction to contract for publishing data...merkle root=%v, mode=%v, size=%v, n=%v, s=%v", b.SigmaMKLRoot, b.Mode, b.Size, b.N, b.S)
Log.Debugf("start send transaction to contract for closing data...merkle root=%v, mode=%v, size=%v, n=%v, s=%v", b.SigmaMKLRoot, b.Mode, b.Size, b.N, b.S)
t := time.Now()
txid, rs, err := closeDataAtContract(bltByte)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const REQUEST_METHOD_GET = "GET"
const DEFAULT_BASIC_CONFGI_FILE = "./basic.json"
const DEFAULT_CONFIG_FILE = "./config.json"
const DEFAULT_KEYSTORE_FILE = "./keystore"
const DEFAULT_KEY_PATH = "./key"
const DEFAULT_KEY_PATH = "./zkPodParam"
const DEFAULT_PUBLISH_BIN_FILE = "./bin/pod_publish"
const DEFAULT_BOB_DIR = "./B"
const DEFAULT_ALICE_DIR = "./A"
Expand All @@ -33,6 +33,7 @@ const TRANSACTION_STATUS_NEGO_FAILED = "NegoFailed"
const TRANSACTION_STATUS_RECEIVED_REQUEST = "requested"
const TRANSACTION_STATUS_INVALID_REQUEST = "invalidRequest"
const TRANSACTION_STATUS_RECEIVED_REQUEST_FAILED = "requestFailed"
const TRANSACTION_STATUS_RECEIVED_DEPOSIT_NOT_ENOUGH = "depositNotEnough"
const TRANSACTION_STATUS_RECEIVED_RESPONSE = "responsed"
const TRANSACTION_STATUS_GENERATE_RESPONSE = "generateResponse"
const TRANSACTION_STATUS_SEND_RESPONSE_FAILED = "responseFailed"
Expand Down
16 changes: 15 additions & 1 deletion contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func readScrtForVRFQ(sessionID string, AliceAddr string, BobAddr string, Log ILo
return secret, errors.New("No secret to be read")
}

func verifyDeposit(AliceAddr string, BobAddr string, value int64) (bool, error) {
func calcuDeposit(AliceAddr string, BobAddr string, value int64) (bool, error) {
dpst, err := ZkPoDExchangeClient.ZkPoDExchangeCaller.BobDeposits(&bind.CallOpts{}, common.HexToAddress(BobAddr), common.HexToAddress(AliceAddr))
if err != nil {
return false, fmt.Errorf("failed to read deposit. err=%v", err)
Expand All @@ -769,6 +769,20 @@ func verifyDeposit(AliceAddr string, BobAddr string, value int64) (bool, error)
return true, nil
}

func checkDeposit(AliceAddr string, BobAddr string, value int64) (bool, err) {
dpst, err := ZkPoDExchangeClient.ZkPoDExchangeCaller.BobDeposits(&bind.CallOpts{}, common.HexToAddress(BobAddr), common.HexToAddress(AliceAddr))
if err != nil {
return false, fmt.Errorf("failed to read deposit. err=%v", err)
}
if dpst.Value.Int64() < value {
return false, nil
}
if dpst.UnDepositAt != 0 && dpst.UnDepositAt+28800 < time.Now().Unix()+600 && dpst.Stat == 1 {
return false, nil
}
return true, nil
}

func calcuBltKey(b Bulletin) ([32]byte, error) {
size, _ := strconv.ParseUint(b.Size, 10, 64)
s, _ := strconv.ParseUint(b.S, 10, 64)
Expand Down
Loading

0 comments on commit 520eefa

Please sign in to comment.