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

Add claim records for localnet #260

Merged
merged 16 commits into from
Feb 8, 2024
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ var (
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner},
claimmoduletypes.ModuleName: {authtypes.Minter},
arkeomoduletypes.ModuleName: {},
arkeomoduletypes.ReserveName: {},
arkeomoduletypes.ProviderName: {},
Expand Down
8 changes: 2 additions & 6 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,8 @@ paths:
type: string
- name: chain
in: query
required: false
type: string
enum:
- ARKEO
- ETHEREUM
default: ARKEO
required: true
type: integer
tags:
- Query
/arkeo/claim/params:
Expand Down
29 changes: 29 additions & 0 deletions scripts/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ add_account() {
mv /tmp/genesis.json ~/.arkeo/config/genesis.json
}

add_claim_records() {
jq --arg CHAIN "$1" --arg ADDRESS "$2" --arg AMOUNTCLAIM "$3" --arg AMOUNTVOTE "$4" --arg AMOUNTDELEGATE "$5" --arg ISTRANSFERABLE "$6" '.app_state.claimarkeo.claim_records += [{
"chain": $CHAIN,
"address": $ADDRESS,
"amount_claim": { "denom": "uarkeo", "amount": $AMOUNTCLAIM },
"amount_vote": { "denom": "uarkeo", "amount": $AMOUNTVOTE },
"amount_delegate": { "denom": "uarkeo", "amount": $AMOUNTDELEGATE },
"is_transferable": true,
}]' <~/.arkeo/config/genesis.json >/tmp/genesis.json
mv /tmp/genesis.json ~/.arkeo/config/genesis.json
}

if [ ! -f ~/.arkeo/config/priv_validator_key.json ]; then
# remove the original generate genesis file, as below will init chain again
rm -rf ~/.arkeo/config/genesis.json
Expand All @@ -64,6 +76,7 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then

if [ "$NET" = "mocknet" ] || [ "$NET" = "testnet" ]; then
add_module tarkeo1d0m97ywk2y4vq58ud6q5e0r3q9khj9e3unfe4t $TOKEN 10000000000000000 'arkeo-reserve' # reserve, 100m
add_module tarkeo14tmx70mvve3u7hfmd45vle49kvylk6s2wllxny $TOKEN 10000000000000000 'claimarkeo'

echo "shoulder heavy loyal save patient deposit crew bag pull club escape eyebrow hip verify border into wire start pact faint fame festival solve shop" | arkeod keys add alice --keyring-backend test --recover
ALICE=$(arkeod keys show alice -a --keyring-backend test)
Expand All @@ -72,6 +85,22 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then
echo "clog swear steak glide artwork glory solution short company borrow aerobic idle corn climb believe wink forum destroy miracle oak cover solid valve make" | arkeod keys add bob --keyring-backend test --recover
BOB=$(arkeod keys show bob -a --keyring-backend test)
add_account "$BOB" $TOKEN 1000000000000000 # bob, 10m
add_claim_records "ARKEO" "$BOB" 1000 1000 1000 true

add_claim_records "ARKEO" "tarkeo19rhn0qgk227zxv8475arky0fhhhy9n9dh6nrj9" 500000 500000 500000 true
add_account "tarkeo19rhn0qgk227zxv8475arky0fhhhy9n9dh6nrj9" $TOKEN 1000000000000000

add_claim_records "ARKEO" "tarkeo1xrz7z3zwtpc45xm72tpnevuf3wn53re8q4u4nr" 500000 500000 500000 true
add_account "tarkeo1xrz7z3zwtpc45xm72tpnevuf3wn53re8q4u4nr" $TOKEN 1000000000000000

add_account "tarkeo1xfpnvwphxyeyydfjxu652veegyuygsjpxppnqsesxsu5xv2px3pngveegserg33saudhje" $TOKEN 1000000000000000
add_claim_records "ARKEO" "tarkeo1xfpnvwphxyeyydfjxu652veegyuygsjpxppnqsesxsu5xv2px3pngveegserg33saudhje" 500000 500000 500000 true

add_claim_records "ETHEREUM" "0x92E14917A0508Eb56C90C90619f5F9Adbf49f47d" 500000 600000 700000 true

# enable CORs on testnet/localnet
sed -i 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' ~/.arkeo/config/app.toml
sed -i 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["*"\]/g' ~/.arkeo/config/config.toml
fi

sed -i 's/"stake"/"uarkeo"/g' ~/.arkeo/config/genesis.json
Expand Down
4 changes: 0 additions & 4 deletions scripts/validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ if [ ! -f ~/.arkeo/config/genesis.json ]; then
# fetch genesis file from seed node
curl -sL "$GENESIS/genesis" | jq '.result.genesis' >~/.arkeo/config/genesis.json

# fetch node id
SEED_ID=$(curl -sL "$RPC/status" | jq -r .result.node_info.id)
SEEDS="$SEED_ID@$SEED"

sed -i 's/enable = false/enable = true/g' ~/.arkeo/config/app.toml
sed -i 's/127.0.0.1:26657/0.0.0.0:26657/g' ~/.arkeo/config/config.toml
sed -i "s/seeds = \"\"/seeds = \"$PEER_ID@$SEED\"/g" ~/.arkeo/config/config.toml
Expand Down
4 changes: 2 additions & 2 deletions sentinel/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (p Proxy) auth(next http.Handler) http.Handler {
}
ser, err := common.NewService(serviceName)
if err != nil || ser != contract.Service {
http.Error(w, fmt.Sprintf("contract service doesn't match the serivce name in the path: (%d/%d)", ser, contract.Service), http.StatusUnauthorized)
http.Error(w, fmt.Sprintf("contract service doesn't match the service name in the path: (%d/%d)", ser, contract.Service), http.StatusUnauthorized)
return
}

Expand Down Expand Up @@ -338,7 +338,7 @@ func (p Proxy) paidTier(aa ArkAuth, remoteAddr string) (code int, err error) {
}

if ok := p.isRateLimited(contract.Id, key, int(contract.QueriesPerMinute)); ok {
return http.StatusTooManyRequests, fmt.Errorf("client is ratelimited," + http.StatusText(429))
return http.StatusTooManyRequests, fmt.Errorf("client is rate limited," + http.StatusText(429))
}

claim.Nonce = aa.Nonce
Expand Down
4 changes: 2 additions & 2 deletions test/regression/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ var httpClient = &http.Client{
// Module Addresses
////////////////////////////////////////////////////////////////////////////////////////

// trunk-ignore-all(golangci-lint/gosec)
// trunk-ignore-all(gitleaks/generic-api-key)

// trunk-ignore(trunk/ignore-does-nothing) # Getting weird lint error only on CI and running locally works fine
// trunk-ignore-all(golangci-lint/gosec)
const (
ModuleAddrBondedTokensPool = "tarkeo1fl48vsnmsdzcv85q5d2q4z5ajdha8yu3e79s43"
ModuleAddrNotBondedTokensPool = "tarkeo1tygms3xhhs3yv487phx3dw4a95jn7t7ld7epr9"
Expand Down
2 changes: 1 addition & 1 deletion testnet/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"index": "1",
"owners": []
},
"claim": {
"claimarkeo": {
"module_account_balance": {
"denom": "",
"amount": "0"
Expand Down
4 changes: 2 additions & 2 deletions x/claim/keeper/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ func (k Keeper) GetClaimRecord(ctx sdk.Context, addr string, chain types.Chain)
prefixStore := prefix.NewStore(store, chainToStorePrefix(chain))
addrBytes := []byte(strings.ToLower(addr))
if !prefixStore.Has(addrBytes) {
return types.ClaimRecord{}, nil
return types.ClaimRecord{Chain: chain}, nil
}
bz := prefixStore.Get(addrBytes)

claimRecord := types.ClaimRecord{}
err := k.cdc.Unmarshal(bz, &claimRecord)
if err != nil {
return types.ClaimRecord{}, err
return types.ClaimRecord{Chain: chain}, err
}

return claimRecord, nil
Expand Down
7 changes: 3 additions & 4 deletions x/claim/keeper/msg_server_claim_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ func IsValidClaimSignature(ethAddress, arkeoAdddress, amount, signature string)
return false, fmt.Errorf("invalid signature length: %d", len(sigHex))
}

// if sigHex[crypto.RecoveryIDOffset] != 27 && sigHex[crypto.RecoveryIDOffset] != 28 {
// return false, fmt.Errorf("invalid recovery id: %d", sigHex[64])
// }
// sigHex[64] -= 27
if sigHex[crypto.RecoveryIDOffset] == 27 || sigHex[crypto.RecoveryIDOffset] == 28 {
sigHex[crypto.RecoveryIDOffset] -= 27 // Transform yellow paper V from 27/28 to 0/1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbarraford This was needed to verify signatures. Would like your eye on it

}

pubKeyRaw, err := crypto.Ecrecover(rawDataHash.Bytes(), sigHex)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion x/claim/keeper/query_claim_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ func TestClaimRecord(t *testing.T) {
Chain: types.ETHEREUM,
}
resp, _ = keepers.ClaimKeeper.ClaimRecord(ctx, &req)
require.Equal(t, *resp.ClaimRecord, types.ClaimRecord{})
require.Equal(t, *resp.ClaimRecord, types.ClaimRecord{Chain: types.ETHEREUM})
}
Loading