This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.find_by!(email: "[email protected]") | |
mutex = Thread::Mutex.new | |
threads = [] | |
5.times do | |
threads << Thread.new do | |
CalculateUserBalanceJob.perform_now(user.id, mutex) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.find_by!(email: "[email protected]") | |
threads = [] | |
5.times do | |
threads << Thread.new do | |
CalculateUserBalanceJob.perform_now(user.id) | |
end | |
end | |
threads.each(&:join) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ApplicationRecord | |
has_one :user_balance, dependent: :destroy | |
validates :email, presence: true, uniqueness: { case_sensitive: false } | |
after_create :create_user_balance | |
private | |
def create_user_balance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CalculateUserBalanceJob < ApplicationJob | |
queue_as :default | |
def perform(user_id) | |
user = User.find(user_id) | |
puts "#{Thread.current.object_id} -> Calculating balance for user: #{user.email}" | |
user_balance = user.user_balance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UserBalance < ApplicationRecord | |
belongs_to :user, inverse_of: :user_balance | |
validates :user_id, uniqueness: true | |
validates :balance, numericality: { greater_than_or_equal_to: 0 } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(saleActive, "TalentCommunitySale: Sale is not active"); | |
require( | |
paymentToken.allowance(msg.sender, address(this)) >= 100 * 10**tokenDecimals, | |
"TalentCommunitySale: Insufficient allowance" | |
); | |
require(tier1Bought < TIER1_MAX_BUYS, "TalentCommunitySale: Tier 1 sold out"); | |
require(!listOfBuyers[msg.sender], "TalentCommunitySale: Address already bought"); | |
require(paymentToken.transferFrom(msg.sender, receivingWallet, 100 * 10**tokenDecimals), "Transfer failed"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This script lists the Farcaster client apps that a Farcaster account has | |
registered as client apps. Farcaster apps are _account keys_ registered | |
on-chain, in Optimism. We are using KeyRegistry contract to read the | |
number and keys of an FID. | |
*/ | |
import { ethers } from "hardhat"; | |
import loadContractAbi from "./loadContractAbi"; | |
const KEY_REGISTRY_CONTRACT_ADDRESS = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"inputs": [ | |
{ | |
"internalType": "address", | |
"name": "_idRegistry", | |
"type": "address" | |
}, | |
{ | |
"internalType": "address", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HardhatUserConfig, vars } from "hardhat/config"; | |
import "@nomicfoundation/hardhat-toolbox"; | |
const ALCHEMY_API_KEY = vars.get("ALCHEMY_API_KEY"); | |
const ACCOUNT_PRIVATE_KEY = vars.get("ACCOUNT_PRIVATE_KEY") | |
const config: HardhatUserConfig = { | |
solidity: "0.8.24", | |
networks: { | |
optimism: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load dependencies | |
const { expect } = require("chai"); | |
require("@nomiclabs/hardhat-ethers"); | |
require("@nomicfoundation/hardhat-chai-matchers"); | |
// Start test block | |
describe("Box", function () { | |
const value = 42n; |