2024-10-03 00:00:41 +02:00
|
|
|
import json
|
2023-11-18 20:20:18 +01:00
|
|
|
from pathlib import Path
|
|
|
|
import dotenv
|
2023-12-13 20:00:03 +01:00
|
|
|
|
2025-01-02 09:14:21 +01:00
|
|
|
from nostr_dvm.framework import DVMFramework
|
2024-10-03 00:00:41 +02:00
|
|
|
from nostr_dvm.tasks.generic_dvm import GenericDVM
|
2023-12-13 20:00:03 +01:00
|
|
|
from nostr_dvm.utils.admin_utils import AdminConfig
|
2024-10-31 12:50:00 +01:00
|
|
|
from nostr_dvm.utils.dvmconfig import build_default_config
|
2024-10-03 00:00:41 +02:00
|
|
|
from nostr_dvm.utils.nip89_utils import NIP89Config, check_and_set_d_tag
|
|
|
|
from nostr_sdk import Keys, Kind
|
2023-11-18 20:20:18 +01:00
|
|
|
|
2023-11-20 22:09:38 +01:00
|
|
|
|
2023-11-24 21:29:24 +01:00
|
|
|
|
2024-10-03 00:00:41 +02:00
|
|
|
def playground(announce=False):
|
2025-01-02 09:14:21 +01:00
|
|
|
framework = DVMFramework()
|
|
|
|
|
2023-12-01 19:11:13 +01:00
|
|
|
admin_config = AdminConfig()
|
2024-10-03 00:00:41 +02:00
|
|
|
admin_config.REBROADCAST_NIP89 = announce
|
|
|
|
admin_config.REBROADCAST_NIP65_RELAY_LIST = announce
|
|
|
|
admin_config.UPDATE_PROFILE = announce
|
|
|
|
|
|
|
|
name = "Generic DVM"
|
|
|
|
identifier = "a_very_generic_dvm" # Chose a unique identifier in order to get a lnaddress
|
|
|
|
dvm_config = build_default_config(identifier)
|
|
|
|
dvm_config.KIND = Kind(5050) # Manually set the Kind Number (see data-vending-machines.org)
|
|
|
|
|
|
|
|
# Add NIP89
|
|
|
|
nip89info = {
|
|
|
|
"name": name,
|
2024-11-22 11:14:39 +01:00
|
|
|
"picture": "https://image.nostr.build/28da676a19841dcfa7dcf7124be6816842d14b84f6046462d2a3f1268fe58d03.png",
|
2024-10-03 00:00:41 +02:00
|
|
|
"about": "I'm just a demo DVM, not doing much.'",
|
2024-11-22 19:18:44 +01:00
|
|
|
"supportsEncryption": True,
|
|
|
|
"acceptsNutZaps": dvm_config.ENABLE_NUTZAP,
|
2024-10-03 00:00:41 +02:00
|
|
|
"nip90Params": {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nip89config = NIP89Config()
|
2024-11-22 11:14:39 +01:00
|
|
|
nip89config.DTAG = check_and_set_d_tag(identifier, name, dvm_config.PRIVATE_KEY, nip89info["picture"])
|
2024-10-03 00:00:41 +02:00
|
|
|
nip89config.CONTENT = json.dumps(nip89info)
|
|
|
|
|
|
|
|
options = {
|
|
|
|
"some_option": "#RunDVM",
|
|
|
|
}
|
|
|
|
|
|
|
|
dvm = GenericDVM(name=name, dvm_config=dvm_config, nip89config=nip89config,
|
|
|
|
admin_config=admin_config, options=options)
|
|
|
|
|
|
|
|
async def process(request_form):
|
|
|
|
options = dvm.set_options(request_form)
|
|
|
|
result = "The result of the DVM is: "
|
|
|
|
result += options["some_option"]
|
|
|
|
print(result)
|
|
|
|
return result
|
|
|
|
|
|
|
|
dvm.process = process # overwrite the process function with the above one
|
2025-01-02 09:14:21 +01:00
|
|
|
framework.add(dvm)
|
|
|
|
|
|
|
|
framework.run()
|
2023-11-18 20:20:18 +01:00
|
|
|
|
2023-11-24 17:20:29 +01:00
|
|
|
if __name__ == '__main__':
|
2023-11-18 20:20:18 +01:00
|
|
|
env_path = Path('.env')
|
2023-12-19 11:36:25 +01:00
|
|
|
if not env_path.is_file():
|
|
|
|
with open('.env', 'w') as f:
|
2023-12-19 15:46:30 +01:00
|
|
|
print("Writing new .env file")
|
2023-12-19 11:36:25 +01:00
|
|
|
f.write('')
|
2023-11-18 20:20:18 +01:00
|
|
|
if env_path.is_file():
|
|
|
|
print(f'loading environment from {env_path.resolve()}')
|
|
|
|
dotenv.load_dotenv(env_path, verbose=True, override=True)
|
|
|
|
else:
|
|
|
|
raise FileNotFoundError(f'.env file not found at {env_path} ')
|
2024-10-03 00:00:41 +02:00
|
|
|
announce = False
|
|
|
|
|
|
|
|
playground(announce=announce)
|