def sendBittransfer(payee_username, amount, description=""): """Create and redeem a BitTransfer.""" wallet = Wallet() username = Config().username bittransfer, signature = createBittransfer( wallet, username, payee_username, amount, description) return redeemBittransfer(bittransfer, signature, payee_username)
def __init__(self, url, wallet=None): """Instantiate a Test Payment Channel Server interface for the specified URL. Args: url (str): URL of Test server. wallet (two1.wallet.Wallet): Wallet instance. Returns: TestPaymentChannelServer: instance of TestPaymentChannelServer. """ super().__init__() self._wallet = wallet if wallet else Wallet()
def main(ctx, json): """Manage payment channels. The `21 channels` command is used for creating, opening, closing, and conducting diagnostics for the payment channel micropayments protocol. After opening a channel with a merchant, making a payment returns a token, which the merchant will accept as proof of payment within the 402 payments protocol. Example of opening a channel, making payments, and closing the channel: $ channels open https://mkt.21.co/21dotco/payments/channel 100000 120\n $ channels pay https://mkt.21.co/21dotco/payments/channel 100\n $ channels pay https://mkt.21.co/21dotco/payments/channel 100\n $ channels pay https://mkt.21.co/21dotco/payments/channel 100\n $ channels info https://mkt.21.co/21dotco/payments/channel\n $ channels close https://mkt.21.co/21dotco/payments/channel\n """ client = PaymentChannelClient(Wallet(WALLET_PATH), CHANNELS_DB_PATH) ctx.obj = {'client': client, 'json': json}
def request(*args, payment_method=None, **kwargs): """Instantiate, or use a cached BitRequests object, and make a request.""" global _requests global _current_method global _current_wallet payment_method = payment_method or _current_method if not _current_wallet: from two1.wallet import Wallet _current_wallet = Wallet() if payment_method not in _requests: if payment_method == OFF_CHAIN: from two1.server.machine_auth_wallet import MachineAuthWallet _requests[_current_method] = BitTransferRequests( MachineAuthWallet(_current_wallet)) elif payment_method == ON_CHAIN: _requests[_current_method] = OnChainRequests(_current_wallet) elif payment_method == CHANNEL: _requests[_current_method] = ChannelRequests(_current_wallet) else: raise ValueError('That method is not supported.') return _requests[payment_method].request(*args, **kwargs)
import click # import from the 21 Bitcoin Developer Library from two1.commands.config import Config from two1.wallet import Wallet from two1.bitrequests import BitTransferRequests username = Config().username wallet = Wallet() requests = BitTransferRequests(wallet, username) @click.command() @click.argument('file_name', required=False) @click.option('--server', default='localhost:5001', help='ip:port to connect to') def img2txt21(server, file_name): """ Call the img to text api hosted on the micropayments server""" ## If a file isn't specified, read image from stdin if file_name: upload = requests.post('http://' + server + '/upload', files={'file': open(file_name, 'rb')}) else: file = click.get_binary_stream('stdin') file_name = 'test.jpg' upload = requests.post('http://' + server + '/upload', files={'file': (file_name, file)}) # convert image to text
import flask from two1.wallet import Wallet from two1.bitserv.flask import Payment app = flask.Flask(__name__) payment = Payment(app, Wallet()) @app.route('/hello') @payment.required(5000) def hello(): return "Hello world" if __name__ == "__main__": app.run(host="::", port=500)
import logging import os from transcodeE16 import TranscodeE16 from two1.commands.util import config from two1.wallet import Wallet from two1.bitrequests import BitTransferRequests requests = BitTransferRequests(Wallet(), config.Config().username) log = logging.getLogger('werkzeug') log.setLevel(logging.INFO) def testDuration(): """ Tests getting the duration for a sample video. """ try: log.warning("In testDuration()") dataDir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data') # Create the speed testing client transcoder = TranscodeE16(dataDir) duration = transcoder.getDuration('http://www.esixteen.co/video/sample.mp4') log.info("Success!") log.info("Duration test completed with duration: {}", duration) except Exception as err: log.warning('Client test failed')
#!/usr/bin/env python3 from two1.wallet import Wallet from two1.bitrequests import BitTransferRequests import sys # set up bitrequest client for BitTransfer requests wallet = Wallet() requests = BitTransferRequests(wallet) payout_address=wallet.get_payout_address() # server address # TODO: URL from cmdline port=4000 server_url = 'http://localhost:{}/'.format(port) def play(): # get the question from the server print("we are sending 100 satoshis and expecting them back") url=server_url + 'test?payout_address={}'.format(payout_address) res = requests.get(url=url) print(res.text) if __name__ == '__main__': play()