<commit_before>(ns status-im.utils.ethereum.stickers
  (:require [status-im.utils.ethereum.core :as ethereum]
            [status-im.utils.ethereum.abi-spec :as abi-spec]))

(def contracts
  {:mainnet nil
   :testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"
   :rinkeby nil})

(defn pack-count [web3 contract cb]
  "Returns number of packs rigestered in the contract"
  (ethereum/call web3
                 (ethereum/call-params contract "packCount()")
                 (fn [_ count] (cb (ethereum/hex->int count)))))

(defn pack-data [web3 contract pack-id cb]
  "Returns vector of pack data parameters by pack id: [category owner mintable timestamp price contenthash]"
  (ethereum/call web3
                 (ethereum/call-params contract "getPackData(uint256)" (ethereum/int->hex pack-id))
                 (fn [_ data]
                   (cb (when data (abi-spec/decode (subs data 2) ["bytes4[]" "address" "bool" "uint256" "uint256" "bytes"]))))))

(defn owned-tokens [web3 contract address cb]
  "Returns vector of owned tokens ids in the contract by address"
  (ethereum/call web3
                 (ethereum/call-params contract "tokensOwnedBy(address)" (ethereum/normalized-address address))
                 (fn [_ data]
                   (cb (when data (first (abi-spec/decode (subs data 2) ["uint256[]"])))))))

(defn token-pack-id [web3 contract token cb]
  "Returns pack id in the contract by token id"<commit_msg>docstring have to be placed before arglist in defn<commit_after>(ns status-im.utils.ethereum.stickers
  (:require [status-im.utils.ethereum.core :as ethereum]
            [status-im.utils.ethereum.abi-spec :as abi-spec]))

(def contracts
  {:mainnet nil
   :testnet "0x39d16CdB56b5a6a89e1A397A13Fe48034694316E"
   :rinkeby nil})

(defn pack-count
  "Returns number of packs rigestered in the contract"
  [web3 contract cb]
  (ethereum/call web3
                 (ethereum/call-params contract "packCount()")
                 (fn [_ count] (cb (ethereum/hex->int count)))))

(defn pack-data
  "Returns vector of pack data parameters by pack id: [category owner mintable timestamp price contenthash]"
  [web3 contract pack-id cb]
  (ethereum/call web3
                 (ethereum/call-params contract "getPackData(uint256)" (ethereum/int->hex pack-id))
                 (fn [_ data]
                   (cb (when data (abi-spec/decode (subs data 2) ["bytes4[]" "address" "bool" "uint256" "uint256" "bytes"]))))))

(defn owned-tokens
  "Returns vector of owned tokens ids in the contract by address"
  [web3 contract address cb]
  (ethereum/call web3
                 (ethereum/call-params contract "tokensOwnedBy(address)" (ethereum/normalized-address address))
                 (fn [_ data]
                   (cb (when data (first (abi-spec/decode (subs data 2) ["uint256[]"])))))))

(defn token-pack-id
  "Returns pack id in the contract by token id"
  [web3 contract token cb]
{'fraction_non_alphanumeric': 0.12039903680770554, 'fraction_numerical': 0.03439972480220158, 'mean_word_length': 2.989026063100137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5314136', 'n_tokens_mistral': 1004, 'n_tokens_neox': 939, 'n_words': 273}