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

V8/new installer #3620

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 148 additions & 66 deletions installer/installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,87 @@ install_node() {
# Change directory to ot-node/current
cd $OTNODE_DIR

# Set node environment to testnet
nodeEnv="testnet"
print_color $CYAN "🌐 Setting up node for Base Sepolia (Testnet) environment"
# Request node environment with strict input validation
while true; do
read -p "Please select node environment: (Default: Mainnet) [T]estnet [M]ainnet [E]xit " choice
case "$choice" in
[tT]* ) nodeEnv="testnet"; break;;
[mM]* ) nodeEnv="mainnet"; break;;
[eE]* ) text_color $RED "Installer stopped by user"; exit;;
* ) text_color $RED "Invalid choice. Please enter either [T]estnet, [M]ainnet, or [E]xit."; continue;;
esac
done
echo "NODE_ENV=$nodeEnv" >> $OTNODE_DIR/.env

# Set blockchain options for testnet
blockchain_options=("Base-Sepolia")
base_blockchain_id=84532
# Set blockchain options based on the selected environment
if [ "$nodeEnv" == "mainnet" ]; then
blockchain_options=("OriginTrail Parachain" "Gnosis" "Base")
otp_blockchain_id=2043
gnosis_blockchain_id=100
base_blockchain_id=8453
else
blockchain_options=("OriginTrail Parachain" "Gnosis" "Base-Sepolia")
otp_blockchain_id=20430
gnosis_blockchain_id=10200
base_blockchain_id=84532
fi

# Ask user which blockchains to connect to
selected_blockchains=()
checkbox_states=()
for _ in "${blockchain_options[@]}"; do
checkbox_states+=("[ ]")
done

while true; do
clear # Clear the screen for a cleaner display
echo "Please select the blockchains you want to connect your node to:"
for i in "${!blockchain_options[@]}"; do
echo " ${checkbox_states[$i]} $((i+1)). ${blockchain_options[$i]}"
done
echo " [ ] $((${#blockchain_options[@]}+1)). All Blockchains"
echo " Enter 'd' to finish selection"

# Use read -n 1 to read a single character without requiring Enter
read -n 1 -p "Enter the number to toggle selection (1-$((${#blockchain_options[@]}+1))): " choice
echo # Add a newline after the selection

if [[ "$choice" == "d" ]]; then
if [ ${#selected_blockchains[@]} -eq 0 ]; then
text_color $RED "You must select at least one blockchain. Please try again."
read -n 1 -p "Press any key to continue..."
continue
else
break
fi
elif [[ "$choice" =~ ^[1-${#blockchain_options[@]}]$ ]]; then
index=$((choice-1))
if [[ "${checkbox_states[$index]}" == "[ ]" ]]; then
checkbox_states[$index]="[x]"
selected_blockchains+=("${blockchain_options[$index]}")
else
checkbox_states[$index]="[ ]"
selected_blockchains=(${selected_blockchains[@]/${blockchain_options[$index]}})
fi
elif [[ "$choice" == "$((${#blockchain_options[@]}+1))" ]]; then
if [[ "${checkbox_states[-1]}" == "[ ]" ]]; then
for i in "${!checkbox_states[@]}"; do
checkbox_states[$i]="[x]"
done
selected_blockchains=("${blockchain_options[@]}")
else
for i in "${!checkbox_states[@]}"; do
checkbox_states[$i]="[ ]"
done
selected_blockchains=()
fi
else
text_color $RED "Invalid choice. Please enter a number between 1 and $((${#blockchain_options[@]}+1))."
read -n 1 -p "Press any key to continue..."
fi
done

print_color $CYAN "🔗 Connecting to Base-Sepolia (Testnet)"
selected_blockchains=("Base-Sepolia")
text_color $GREEN "Final blockchain selection: ${selected_blockchains[*]}"

CONFIG_DIR=$OTNODE_DIR/..
perform_step touch $CONFIG_DIR/.origintrail_noderc "Configuring node config file"
Expand All @@ -331,7 +401,7 @@ install_node() {
validate_operator_fees() {
local blockchain=$1
while true; do
read -p "$(print_color $CYAN "Enter your operator fee for Base Sepolia (0-100): ")" OPERATOR_FEE
read -p "$(print_color $CYAN "Enter your operator fee for $blockchain (0-100): ")" OPERATOR_FEE
if [[ "$OPERATOR_FEE" =~ ^[0-9]+$ ]] && [ "$OPERATOR_FEE" -ge 0 ] && [ "$OPERATOR_FEE" -le 100 ]; then
print_color $GREEN "✅ Operator fee for $blockchain: $OPERATOR_FEE"
break
Expand All @@ -346,39 +416,23 @@ install_node() {
local blockchain=$1
local blockchain_id=$2

print_color $CYAN "🔧 Configuring Base Sepolia (Testnet)..."
request_operational_wallet_keys $blockchain
local EVM_OP_WALLET_KEYS=$OP_WALLET_KEYS_JSON

print_color $YELLOW "You'll now be asked to input your operational wallets public and private keys (press ENTER to skip)"

local EVM_OP_WALLET_KEYS='[]'
local wallet_index=1
while true; do
read -p "$(print_color $YELLOW "Please insert your operational wallet public key no. $wallet_index: ")" wallet_address
if [ -z "$wallet_address" ]; then
break
fi
print_color $GREEN " EVM operational wallet public key no. $wallet_index: $wallet_address"

read -p "$(print_color $YELLOW "Please insert private key for your operational wallet no. $wallet_index: ")" wallet_private_key
if [ -z "$wallet_private_key" ]; then
break
fi
print_color $GREEN " EVM operational wallet private key no. $wallet_index: $wallet_private_key"

EVM_OP_WALLET_KEYS=$(echo $EVM_OP_WALLET_KEYS | jq '. += [{"address": "'$wallet_address'", "privateKey": "'$wallet_private_key'"}]')
wallet_index=$((wallet_index + 1))
done

read -p "$(print_color $YELLOW "Enter your EVM management wallet address : ")" EVM_MANAGEMENT_WALLET
print_color $GREEN "✅ EVM management wallet address : $EVM_MANAGEMENT_WALLET"
read -p "Enter your EVM management wallet address for $blockchain: " EVM_MANAGEMENT_WALLET
text_color $GREEN "EVM management wallet address for $blockchain: $EVM_MANAGEMENT_WALLET"

read -p "$(print_color $YELLOW "Enter your profile node name : ")" NODE_NAME
print_color $GREEN "✅ Profile shares token name : $NODE_NAME"
print_color $GREEN "✅ Profile node name : $NODE_NAME"


validate_operator_fees $blockchain

read -p "$(print_color $YELLOW "Enter your RPC endpoint: ")" RPC_ENDPOINT
print_color $GREEN "✅ RPC endpoint: $RPC_ENDPOINT"
local RPC_ENDPOINT=""
if [ "$blockchain" == "gnosis" ] || [ "$blockchain" == "base" ]; then
read -p "Enter your $blockchain RPC endpoint: " RPC_ENDPOINT
text_color $GREEN "$blockchain RPC endpoint: $RPC_ENDPOINT"
fi

local jq_filter=$(cat <<EOF
.modules.blockchain.implementation["$blockchain:$blockchain_id"] = {
Expand All @@ -387,52 +441,80 @@ install_node() {
"operationalWallets": $EVM_OP_WALLET_KEYS,
"evmManagementWalletPublicKey": "$EVM_MANAGEMENT_WALLET",
"nodeName": "$NODE_NAME",
"operatorFee": $OPERATOR_FEE,
"rpcEndpoints": ["$RPC_ENDPOINT"]
"operatorFee": $OPERATOR_FEE
}
}
EOF
)

if [ -n "$RPC_ENDPOINT" ]; then
jq_filter+=" | .modules.blockchain.implementation[\"$blockchain:$blockchain_id\"].config.rpcEndpoints = [\"$RPC_ENDPOINT\"]"
fi

jq "$jq_filter" $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp
mv $CONFIG_DIR/origintrail_noderc_tmp $CONFIG_DIR/.origintrail_noderc
chmod 600 $CONFIG_DIR/.origintrail_noderc
}

# Configure Base-Sepolia
configure_blockchain "base" $base_blockchain_id

# Function to configure blockchain events services
configure_blockchain_events_services() {
local blockchain=$1
local blockchain_id=$2

print_color $CYAN "🔧 Configuring Blockchain Events Service for Base Sepolia (Testnet)..."

read -p "$(print_color $YELLOW "Enter your RPC endpoint: ")" RPC_ENDPOINT
print_color $GREEN "✅ RPC endpoint: $RPC_ENDPOINT"
local blockchain=$1
local blockchain_id=$2

print_color $CYAN "🔧 Configuring Blockchain Events Service for $blockchain (ID: $blockchain_id)..."

# Prompt the user for the RPC endpoint
read -p "$(print_color $YELLOW "Enter your RPC endpoint for $blockchain: ")" RPC_ENDPOINT
print_color $GREEN "✅ RPC endpoint: $RPC_ENDPOINT"

# Correct `jq` usage to safely initialize and update the configuration
local jq_filter='
.modules |= (if .blockchainEvents == null then .blockchainEvents = {implementation: {}} else . end) |
.modules.blockchainEvents.implementation |= (if .["ot-ethers"] == null then .["ot-ethers"] = {enabled: false, config: {}} else . end) |
.modules.blockchainEvents.implementation["ot-ethers"].enabled = true |
.modules.blockchainEvents.implementation["ot-ethers"].config |= (if .blockchains == null then .blockchains = [] else . end) |
.modules.blockchainEvents.implementation["ot-ethers"].config |= (if .rpcEndpoints == null then .rpcEndpoints = {} else . end) |
.modules.blockchainEvents.implementation["ot-ethers"].config.blockchains += ["'"$blockchain:$blockchain_id"'"] |
.modules.blockchainEvents.implementation["ot-ethers"].config.rpcEndpoints["'"$blockchain:$blockchain_id"'"] = ["'"$RPC_ENDPOINT"'"]
'

# Apply the configuration changes
if jq "$jq_filter" "$CONFIG_DIR/.origintrail_noderc" > "$CONFIG_DIR/.origintrail_noderc_tmp"; then
mv "$CONFIG_DIR/.origintrail_noderc_tmp" "$CONFIG_DIR/.origintrail_noderc"
chmod 600 "$CONFIG_DIR/.origintrail_noderc"
print_color $GREEN "✅ Successfully configured Blockchain Events Service for $blockchain (ID: $blockchain_id)."
else
print_color $RED "❌ Failed to configure Blockchain Events Service for $blockchain (ID: $blockchain_id)."
exit 1
fi
}

local jq_filter=$(cat <<EOF
.modules.blockchainEvents.implementation["ot-ethers"] = {
"enabled": true,
"config": {
"blockchains": ["$blockchain:$blockchain_id"],
rpcEndpoints: {
"$blockchain:$blockchain_id": ["$RPC_ENDPOINT"]
}
}
}
EOF
)

jq "$jq_filter" $CONFIG_DIR/.origintrail_noderc > $CONFIG_DIR/origintrail_noderc_tmp
mv $CONFIG_DIR/origintrail_noderc_tmp $CONFIG_DIR/.origintrail_noderc
chmod 600 $CONFIG_DIR/.origintrail_noderc
}

# Configure blockchain events service for Base Sepolia
configure_blockchain_events_services "base" $base_blockchain_id
for blockchain in "${selected_blockchains[@]}"; do
case "$blockchain" in
"OriginTrail Parachain")
configure_blockchain "otp" $otp_blockchain_id
;;
"Gnosis")
configure_blockchain "gnosis" $gnosis_blockchain_id
;;
"Base" | "Base-Sepolia")
configure_blockchain "base" $base_blockchain_id
;;
esac
done

for blockchain in "${selected_blockchains[@]}"; do
case "$blockchain" in
"Gnosis")
configure_blockchain_events_services "gnosis" $gnosis_blockchain_id
;;
"Base" | "Base-Sepolia")
configure_blockchain_events_services "base" $base_blockchain_id
;;
esac
done
# Now execute npm install after configuring wallets
print_color $CYAN "📦 Installing npm packages..."
perform_step npm ci --omit=dev --ignore-scripts "Executing npm install"
Expand Down
17 changes: 8 additions & 9 deletions v8-data-migration/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,54 @@ export const ABIs = {
ContentAssetStorageV2: require('./abi/ContentAssetStorageV2.json'),
ContentAssetStorage: require('./abi/ContentAssetStorage.json'),
};

export const BLOCKCHAINS = {
BASE_DEVNET: {
ID: 'base:84532',
ENV: 'devnet',
NAME: 'base_devnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0xBe08A25dcF2B68af88501611e5456571f50327B4',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0xbe08a25dcf2b68af88501611e5456571f50327b4',
},
BASE_TESTNET: {
ID: 'base:84532',
ENV: 'testnet',
NAME: 'base_testnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x9e3071Dc0730CB6dd0ce42969396D716Ea33E7e1',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x9e3071dc0730cb6dd0ce42969396d716ea33e7e1',
},
BASE_MAINNET: {
ID: 'base:8453',
ENV: 'mainnet',
NAME: 'base_mainnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x3bdfA81079B2bA53a25a6641608E5E1E6c464597',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x3bdfa81079b2ba53a25a6641608e5e1e6c464597',
},
GNOSIS_DEVNET: {
ID: 'gnosis:10200',
ENV: 'devnet',
NAME: 'gnosis_devnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x3db64dD0Ac054610d1e2Af9Cca0fbCB1A7f4C2d8',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x3db64dd0ac054610d1e2af9cca0fbcb1a7f4c2d8',
},
GNOSIS_TESTNET: {
ID: 'gnosis:10200',
ENV: 'testnet',
NAME: 'gnosis_testnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0xeA3423e02c8d231532dab1BCE5D034f3737B3638',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0xea3423e02c8d231532dab1bce5d034f3737b3638',
},
GNOSIS_MAINNET: {
ID: 'gnosis:100',
ENV: 'mainnet',
NAME: 'gnosis_mainnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0xf81a8C0008DE2DCdb73366Cf78F2b178616d11DD',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0xf81a8c0008de2dcdb73366cf78f2b178616d11dd',
},
NEUROWEB_TESTNET: {
ID: 'otp:20430',
ENV: 'testnet',
NAME: 'neuroweb_testnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x1A061136Ed9f5eD69395f18961a0a535EF4B3E5f',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x1a061136ed9f5ed69395f18961a0a535ef4b3e5f',
},
NEUROWEB_MAINNET: {
ID: 'otp:2043',
ENV: 'mainnet',
NAME: 'neuroweb_mainnet',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x5cAC41237127F94c2D21dAe0b14bFeFa99880630',
CONTENT_ASSET_STORAGE_CONTRACT_ADDRESS: '0x5cac41237127f94c2d21dae0b14bfefa99880630',
},
};

Expand Down
2 changes: 1 addition & 1 deletion v8-data-migration/triple-store-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export async function insertAssertionsIntoV8UnifiedRepository(
continue;
}

const knowledgeAssetUal = `${ual}/1`;
const knowledgeAssetUal = `${ual.toLowerCase()}/1`;

const publicNQuads = processContent(publicAssertion);
insertQueries.push(`
Expand Down
4 changes: 2 additions & 2 deletions v8-data-migration/v8-data-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

if (assertionsToCheck.length > 0) {
const { tokenId, ual, privateAssertion } = assertionsToCheck[0];
const knowledgeAssetUal = `${ual}/1`;
const knowledgeAssetUal = `${ual.toLowerCase()}/1`;
logger.time(`GETTING KNOWLEDGE COLLECTION NAMED GRAPHS EXIST FOR 1 ASSERTION`);
// eslint-disable-next-line no-await-in-loop
const { exists } = await getKnowledgeCollectionNamedGraphsExist(
Expand Down Expand Up @@ -182,7 +182,7 @@
const promises = [];
for (const assertion of assertionsToCheck) {
const { tokenId, ual, privateAssertion } = assertion;
const knowledgeAssetUal = `${ual}/1`;
const knowledgeAssetUal = `${ual.toLowerCase()}/1`;

promises.push(
getKnowledgeCollectionNamedGraphsExist(
Expand Down Expand Up @@ -436,7 +436,7 @@
logger.info(`Amount of tokenIds left to process: ${tokenIdsToProcessCount}`);

// Process tokens in batches
while (true) {

Check warning on line 439 in v8-data-migration/v8-data-migration.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected constant condition
logger.time('BATCH PROCESSING TIME');

const batchData = await sqliteDb.getBatchOfUnprocessedTokenIds(
Expand Down
Loading