#!/usr/bin/env python # -*- coding: utf-8 -*- import time from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: Timestamp trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_TimestampTrigger']) ######################################################################################################### # Timestamp trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_TimestampTrigger' trigger_type = 'Timestamp' timestamp = int(time.time()) + 5 # 5 seconds in the future # ---------------------------------------------------------------------------------------------------------------------- response = spellbook_call('save_trigger', trigger_name, '-t=%s' % trigger_type, '-ts=%s' % timestamp, '-st=Active') assert response is None response = spellbook_call('get_trigger_config', trigger_name) assert response['trigger_type'] == trigger_type assert response['timestamp'] == timestamp assert response['triggered'] == 0 print('Checking timestamp trigger, should not activate') response = spellbook_call('check_triggers', trigger_name)
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from helpers.hotwallethelpers import get_address_from_wallet from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: triggers') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=[ 'test_trigger_Manual', 'test_trigger_Balance', 'test_trigger_Received', 'test_trigger_Sent', 'test_trigger_Block_height', 'test_trigger_Timestamp' ]) # -------------------------------------------------------------------------------------------------------- trigger_types = [ 'Manual', 'Balance', 'Received', 'Sent', 'Block_height', 'Timestamp' ] for trigger_type in trigger_types: print( '--------------------------------------------------------------------------------------------------------' ) print('Saving trigger of type: %s' % trigger_type) trigger_name = 'test_trigger_%s' % trigger_type response = spellbook_call('save_trigger', trigger_name,
#!/usr/bin/env python # -*- coding: utf-8 -*- from helpers.setupscripthelpers import spellbook_call, clean_up_triggers, clean_up_actions print('Starting Spellbook integration test: TriggerStatus trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=[ 'test_trigger_conditions_TriggerStatusTrigger', 'test_trigger_conditions_TriggerStatusTrigger_A', 'test_trigger_conditions_TriggerStatusTrigger_B' ]) # Clean up actions if necessary clean_up_actions(action_ids=['test_triggerstatus_action']) ######################################################################################################### # TriggerStatus trigger ######################################################################################################### print('Creating previous trigger with webhook action') previous_trigger = 'test_trigger_conditions_TriggerStatusTrigger_A' previous_trigger_status = 'Succeeded' previous_trigger_type = 'Manual' response = spellbook_call('save_trigger', previous_trigger, '-t=%s' % previous_trigger_type, '-st=Active') assert response is None action_name = 'test_triggerstatus_action' webhook = 'http://www.google.com'
# This setup script will create a HTTP POST request trigger that will be used each time a new Voucher request is made # A HTTP POST request must contain the key 'voucher' and must contain a valid bitcoin address # The script will then check if the voucher is valid and send some amount of bitcoin to the address ########################################################################################################## print('Setting up Voucher') print('----------------------------------------------\n') # -------------------------------------------------------------------------------------------------------- # Clean up old triggers and actions first # -------------------------------------------------------------------------------------------------------- clean_up_triggers(trigger_ids=['RedeemVoucher']) # -------------------------------------------------------------------------------------------------------- # Create Triggers # -------------------------------------------------------------------------------------------------------- print('\nCreating Trigger...') trigger_id = 'RedeemVoucher' trigger_type = TriggerType.HTTPPOSTREQUEST script = os.path.join('Voucher', 'RedeemVoucher.py') response = spellbook_call('save_trigger', trigger_id, '--type=%s' % trigger_type, '--script=%s' % script, '--multi', '--status=Active') assert response is None
# must save the distribution as a json file distribution_filename = os.path.join('splitter-distribution.json') save_to_json_file(filename=distribution_filename, data=distribution) ########################################################################################################## print('Setting up Splitter') print('----------------------------------------------\n') print('The address for the splitter is %s' % splitter_address) # -------------------------------------------------------------------------------------------------------- # Clean up old triggers and actions first # -------------------------------------------------------------------------------------------------------- clean_up_triggers(trigger_ids=['Splitter']) clean_up_actions(action_ids=['Splitter']) # -------------------------------------------------------------------------------------------------------- # Create Actions # -------------------------------------------------------------------------------------------------------- print('\nCreating Action...') action_id = 'Splitter' action_type = ActionType.SENDTRANSACTION transaction_type = TransactionType.SEND2MANY # no need to set the amount, all funds in the address will be sent response = spellbook_call( 'save_action', action_id,
# "status": "Created", # "txid": null # } # Upon a new payment request the script will start a transaction listener for the payment, once a transaction is detected the status will be updated # There is also a HTTP GET trigger to request the status of a specified payment request ########################################################################################################## print('Setting up PaymentProcessor') print('----------------------------------------------\n') # -------------------------------------------------------------------------------------------------------- # Clean up old triggers and actions first # -------------------------------------------------------------------------------------------------------- clean_up_triggers(trigger_ids=['PaymentProcessorNewPayment', 'PaymentProcessorPaymentStatus', 'PaymentProcessorTransactionReceived']) # -------------------------------------------------------------------------------------------------------- # Create Triggers # -------------------------------------------------------------------------------------------------------- print('Creating Triggers...') trigger_id = 'PaymentProcessorNewPayment' trigger_type = 'HTTPPostRequest' script = os.path.join('PaymentProcessor', 'PaymentProcessorNewPayment.py') response = spellbook_call('save_trigger', trigger_id, '-t=%s' % trigger_type, '--multi', '-sc=%s' % script) assert response is None
#!/usr/bin/env python # -*- coding: utf-8 -*- from helpers.hotwallethelpers import get_address_from_wallet from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: Received trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_ReceivedTrigger']) ######################################################################################################### # Received trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_ReceivedTrigger' trigger_type = 'Received' # ---------------------------------------------------------------------------------------------------------------------- account = 0 index = 0 address = get_address_from_wallet(account=account, index=index) balance_data = spellbook_call('get_balance', address) amount = balance_data['balance']['received'] print('Creating Received trigger') print('Setting trigger amount higher than current received balance') response = spellbook_call('save_trigger', '-t=%s' % trigger_type, trigger_name, '--reset', '-a=%s' % address,
exit(1) latest_block_data = latest_block() if 'block' not in latest_block_data: print('Unable to get latest block') exit(1) current_block_height = latest_block_data['block']['height'] print('\nCurrent block height: %s' % current_block_height) print('Lottery will pick winner at block height: %s' % (current_block_height + block_height_offset)) # -------------------------------------------------------------------------------------------------------- # Clean up old triggers and actions first # -------------------------------------------------------------------------------------------------------- clean_up_triggers(trigger_ids=['Lottery']) clean_up_actions(action_ids=['Lottery-payout']) # -------------------------------------------------------------------------------------------------------- # Create Actions # -------------------------------------------------------------------------------------------------------- print('\nCreating Action...') action_id = 'Lottery-payout' action_type = ActionType.SENDTRANSACTION transaction_type = TransactionType.SEND2SINGLE response = spellbook_call('save_action', action_id, '--type=%s' % action_type, '--wallet_type=%s' % wallet_type, '--bip44_account=%s' % bip44_account, '--bip44_index=%s' % bip44_index, '--fee_percentage=%s' % lottery_fee_percentage,
#!/usr/bin/env python # -*- coding: utf-8 -*- from helpers.hotwallethelpers import get_address_from_wallet from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: Balance trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_BalanceTrigger']) ######################################################################################################### # Balance trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_BalanceTrigger' trigger_type = 'Balance' # ---------------------------------------------------------------------------------------------------------------------- account = 0 index = 0 address = get_address_from_wallet(account=account, index=index) balance_data = spellbook_call('get_balance', address) amount = balance_data['balance']['final'] print('Creating Balance trigger') print('Setting trigger amount higher than current balance') response = spellbook_call('save_trigger', '-t=%s' % trigger_type, trigger_name, '-st=Active', '-a=%s' % address,
#!/usr/bin/env python # -*- coding: utf-8 -*- from helpers.hotwallethelpers import get_address_from_wallet from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: Sent trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_SentTrigger']) ######################################################################################################### # Sent trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_SentTrigger' trigger_type = 'Sent' # ---------------------------------------------------------------------------------------------------------------------- account = 0 index = 0 address = get_address_from_wallet(account=account, index=index) balance_data = spellbook_call('get_balance', address) amount = balance_data['balance']['sent'] print('Creating Received trigger') print('Setting trigger amount higher than current sent balance') response = spellbook_call('save_trigger', '-t=%s' % trigger_type, trigger_name, '--reset', '-a=%s' % address,
#!/usr/bin/env python # -*- coding: utf-8 -*- from helpers.setupscripthelpers import spellbook_call, clean_up_triggers, clean_up_actions print('Starting Spellbook integration test: trigger with actions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_with_actions']) # Clean up actions if necessary clean_up_actions(action_ids=['test_trigger_action1', 'test_trigger_action2', 'test_trigger_action3', 'test_trigger_action4']) ######################################################################################################### # Trigger with actions ######################################################################################################### trigger_name = 'test_trigger_with_actions' trigger_type = 'Manual' # -------------------------------------------------------------------------------------------------------- print('Saving trigger of type: %s' % trigger_type) response = spellbook_call('save_trigger', trigger_name, '-t=%s' % trigger_type) assert response is None response = spellbook_call('get_trigger_config', trigger_name) assert response['trigger_id'] == trigger_name assert response['trigger_type'] == trigger_type assert response['actions'] == []
#!/usr/bin/env python # -*- coding: utf-8 -*- from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: Manual trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_ManualTrigger']) ######################################################################################################### # Manual trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_ManualTrigger' trigger_type = 'Manual' # ------------------------------------------------------------------------------------------------- print('Creating Manual trigger') response = spellbook_call('save_trigger', trigger_name, '-t=%s' % trigger_type, '-st=Active') assert response is None print('Checking if trigger has not been triggered yet') response = spellbook_call('get_trigger_config', trigger_name) assert response['triggered'] == 0 assert response['trigger_type'] == trigger_type print('Activating Manual trigger') response = spellbook_call('activate_trigger', trigger_name) assert response is None
# Set the dividends fee, in this case we will charge a 1 percent fee each time dividends are given out dividends_fee_percentage = 1.0 dividends_fee_address = get_address_from_wallet(account=bip44_account, index=bip44_index_fee) ########################################################################################################## print( 'Setting up Dividends') print( '----------------------------------------------\n') print( 'The address for the dividends is %s' % dividends_address) # -------------------------------------------------------------------------------------------------------- # Clean up old triggers and actions first # -------------------------------------------------------------------------------------------------------- clean_up_triggers(trigger_ids=['Dividends']) clean_up_actions(action_ids=['Dividends']) # -------------------------------------------------------------------------------------------------------- # Create Actions # -------------------------------------------------------------------------------------------------------- print( '\nCreating Action...') action_id = 'Dividends' action_type = ActionType.SENDTRANSACTION transaction_type = TransactionType.SEND2SIL # no need to set the amount, all funds in the address will be sent response = spellbook_call('save_action', action_id, '--type=%s' % action_type, '--transaction_type=%s' % transaction_type,
# This setup script will create a HTTP POST request trigger that will be used each time a new Notary request is made # A HTTP POST request must contain the key 'message' and must contain a valid op_return message (max 80 characters) # The script will then return json data containing the following keys: 'address', 'value', 'request_id', 'timeout' # The script will create a new trigger to monitor payment and add an action that will send a transaction with the # requested OP_RETURN output once the payment is confirmed ########################################################################################################## print('Setting up Notary') print('----------------------------------------------\n') # -------------------------------------------------------------------------------------------------------- # Clean up old triggers and actions first # -------------------------------------------------------------------------------------------------------- clean_up_triggers(trigger_ids=['Notary-request']) # -------------------------------------------------------------------------------------------------------- # Create Triggers # -------------------------------------------------------------------------------------------------------- print('\nCreating Trigger...') trigger_id = 'Notary-request' trigger_type = TriggerType.HTTPPOSTREQUEST script = 'Notary\Notary.py' response = spellbook_call('save_trigger', trigger_id, '--type=%s' % trigger_type, '--script=%s' % script, '--multi') assert response is None print('HTTP POST endpoint created')
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: Recurring trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_RecurringTrigger']) ######################################################################################################### # Recurring trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_RecurringTrigger' trigger_type = 'Recurring' begin_time = int(time.time()) + 10 # 10 seconds in the future end_time = int(time.time()) + 60 # 60 seconds in the future interval = 10 # ---------------------------------------------------------------------------------------------------------------------- response = spellbook_call('save_trigger', trigger_name, '-t=%s' % trigger_type, '-bt=%s' % begin_time, '-et=%s' % end_time, '-i=%s' % interval, '-st=Active') assert response is None response = spellbook_call('get_trigger_config', trigger_name) assert response['trigger_type'] == trigger_type assert response['begin_time'] == begin_time assert response['end_time'] == end_time assert response['interval'] == interval
#!/usr/bin/env python # -*- coding: utf-8 -*- import time from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: DeadMansSwitch trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers( trigger_ids=['test_trigger_conditions_DeadMansSwitchTrigger']) ######################################################################################################### # DeadMansSwitch trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_DeadMansSwitchTrigger' trigger_type = 'DeadMansSwitch' timeout = 60 # 60 seconds warning_email = '*****@*****.**' response = spellbook_call('save_trigger', trigger_name, '-t=%s' % trigger_type, '-ti=%s' % timeout, '-we=%s' % warning_email, '-st=Active') assert response is None response = spellbook_call('get_trigger_config', trigger_name) assert response['trigger_type'] == trigger_type assert response['timeout'] == timeout assert response['warning_email'] == warning_email assert response['triggered'] == 0
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import simplejson from helpers.ipfshelpers import IPFS_API from helpers.hotwallethelpers import get_address_from_wallet, get_private_key_from_wallet from helpers.setupscripthelpers import spellbook_call, clean_up_triggers from helpers.messagehelpers import sign_message, verify_message print('Starting Spellbook integration test: SignedMessage trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_SignedMessageTrigger']) ######################################################################################################### # SignedMessage trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_SignedMessageTrigger' trigger_type = 'SignedMessage' # ---------------------------------------------------------------------------------------------------------------------- response = spellbook_call('save_trigger', trigger_name, '-t=%s' % trigger_type, '-st=Active') assert response is None response = spellbook_call('get_trigger_config', trigger_name) assert response['trigger_type'] == trigger_type assert response['triggered'] == 0
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys import requests import simplejson from helpers.setupscripthelpers import spellbook_call, clean_up_triggers from helpers.configurationhelpers import get_host, get_port print('Starting Spellbook integration test: HTTP DELETE request trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_HTTPDeleteRequest_Trigger']) ######################################################################################################### # HTTP DELETE request trigger ######################################################################################################### trigger_id = 'test_trigger_conditions_HTTPDeleteRequest_Trigger' trigger_type = 'HTTPDeleteRequest' script = 'Echo.py' # ------------------------------------------------------------------------------------------------- print('Creating HTTP DELETE request trigger') response = spellbook_call('save_trigger', trigger_id, '-t=%s' % trigger_type, '-sc=%s' % script, '-st=Active', '--multi') assert response is None print('Checking if trigger has not been triggered yet') response = spellbook_call('get_trigger_config', trigger_id) assert response['triggered'] is 0
#!/usr/bin/env python # -*- coding: utf-8 -*- from helpers.setupscripthelpers import spellbook_call, clean_up_triggers print('Starting Spellbook integration test: BlockHeight trigger conditions') print('----------------------------------------------\n') # Clean up triggers if necessary clean_up_triggers(trigger_ids=['test_trigger_conditions_BlockHeightTrigger']) ######################################################################################################### # Blockheight trigger ######################################################################################################### trigger_name = 'test_trigger_conditions_BlockHeightTrigger' trigger_type = 'Block_height' # ------------------------------------------------------------------------------------------------- print('Creating Block_height trigger') response = spellbook_call('get_latest_block') latest_block_height = response['block']['height'] assert isinstance(latest_block_height, int) and latest_block_height > 0 print( 'set block_height to 1 block in the future and 0 conditions, this should not trigger yet' ) response = spellbook_call('save_trigger', trigger_name, '-t=%s' % trigger_type, '-b=%d' % (latest_block_height + 1), '-c=0', '-st=Active') assert response is None