def default_msig_txn(context, amt, note): params = context.acl.suggested_params_as_object() context.last_round = params.first if note == "none": note = None else: note = base64.b64decode(note) context.msig = transaction.Multisig(1, 1, context.accounts) context.txn = transaction.PaymentTxn(context.msig.address(), params, context.accounts[1], int(amt), note=note) context.mtx = transaction.MultisigTransaction(context.txn, context.msig) context.pk = context.accounts[0]
def msig_addresses(context, addresses): addresses = addresses.split(" ") context.msig = transaction.Multisig(1, 2, addresses)
return transaction.PaymentTxn(**txn) # generate three accounts gen_alc = generateAccounts() print(gen_alc) # Generate a multisignature account req = 2 # number of Signature(s) required vers = 1 # version of Signature hisAddress = (accounts['account_1']['alc_address']) hisPrivateKey = (accounts['account_1']['pkey']) spendAccount = (accounts['account_2']['alc_address']) # create the rule multsig = transaction.Multisig(vers, req, [hisAddress, wifeAddress]) i = multsig.get_multisig_account() print(i) # # create a transaction savingAlcAddr = multsig.address() # trx = create_transaction(savingAlcAddr, spendAccount, 401000) trxn = txnfield(savingAlcAddr, spendAccount, 401000) # trxn = transaction.PaymentTxn(**trxn) multisigtxn = transaction.MultisigTransaction( trxn, multsig) # create a SignedTransaction object multisigtxn.sign(wifePrivateKey) # signer1 signs the transaction multisigtxn.sign(hisPrivateKey) # signer2 signs the transaction getConnected.send_transaction(multisigtxn, headers={'content-type': 'application/x-binary'})
# Example: manipulating multisig transactions import tokens from algosdk import account, algod, encoding from algosdk.future import transaction # generate three accounts private_key_1, account_1 = account.generate_account() private_key_2, account_2 = account.generate_account() private_key_3, account_3 = account.generate_account() # create a multisig account version = 1 # multisig version threshold = 2 # how many signatures are necessary msig = transaction.Multisig(version, threshold, [account_1, account_2]) # get suggested parameters acl = algod.AlgodClient(tokens.algod_token, tokens.algod_address) suggested_params = acl.suggested_params_as_object() # create a transaction sender = msig.address() amount = 10000 txn = transaction.PaymentTxn(sender, suggested_params, account_3, amount) # create a SignedTransaction object mtx = transaction.MultisigTransaction(txn, msig) # sign the transaction mtx.sign(private_key_1) mtx.sign(private_key_2)
def test_wallet(self): # initialize wallet w = wallet.Wallet(wallet_name, wallet_pswd, self.kcl) # get master derivation key mdk = w.export_master_derivation_key() # get mnemonic mn = w.get_mnemonic() # make sure mnemonic can be converted back to mdk self.assertEqual(mdk, mnemonic.to_master_derivation_key(mn)) # generate account with account and check if it's valid private_key_1, account_1 = account.generate_account() # import generated account import_key = w.import_key(private_key_1) self.assertEqual(import_key, account_1) # check that the account is in the wallet keys = w.list_keys() self.assertIn(account_1, keys) # generate account with kmd account_2 = w.generate_key() private_key_2 = w.export_key(account_2) # get suggested parameters and fee gh = self.acl.versions()['genesis_hash_b64'] rnd = int(self.acl.status()['lastRound']) sp = transaction.SuggestedParams(0, rnd, rnd + 100, gh) # create transaction txn = transaction.PaymentTxn(self.account_0, sp, account_1, 100000) # sign transaction with wallet signed_kmd = w.sign_transaction(txn) # get self.account_0 private key private_key_0 = w.export_key(self.account_0) # sign transaction with account signed_account = txn.sign(private_key_0) # check that signing both ways results in the same thing self.assertEqual(encoding.msgpack_encode(signed_account), encoding.msgpack_encode(signed_kmd)) # create multisig account and transaction msig = transaction.Multisig(1, 2, [account_1, account_2]) txn = transaction.PaymentTxn(msig.address(), sp, self.account_0, 1000) # import multisig account msig_address = w.import_multisig(msig) # check that the multisig account is listed msigs = w.list_multisig() self.assertIn(msig_address, msigs) # export multisig account exported = w.export_multisig(msig_address) self.assertEqual(len(exported.subsigs), 2) # create multisig transaction mtx = transaction.MultisigTransaction(txn, msig) # sign the multisig using kmd msig_1 = w.sign_multisig_transaction(account_1, mtx) signed_kmd = w.sign_multisig_transaction(account_2, msig_1) # sign the multisig offline mtx1 = transaction.MultisigTransaction(txn, msig) mtx1.sign(private_key_1) mtx2 = transaction.MultisigTransaction(txn, msig) mtx2.sign(private_key_2) signed_account = transaction.MultisigTransaction.merge([mtx1, mtx2]) # check that they are the same self.assertEqual(encoding.msgpack_encode(signed_account), encoding.msgpack_encode(signed_kmd)) # delete accounts del_1 = w.delete_key(account_1) del_2 = w.delete_key(account_2) del_3 = w.delete_multisig(msig_address) self.assertTrue(del_1) self.assertTrue(del_2) self.assertTrue(del_3) # test renaming the wallet w.rename(wallet_name + "1") self.assertEqual(wallet_name + "1", w.info()["wallet"]["name"]) w.rename(wallet_name) self.assertEqual(wallet_name, w.info()["wallet"]["name"]) # test releasing the handle w.release_handle() self.assertRaises(error.KMDHTTPError, self.kcl.get_wallet, w.handle) # test handle automation w.info()
def test_multisig(self): # get the default wallet wallets = self.kcl.list_wallets() wallet_id = None for w in wallets: if w["name"] == wallet_name: wallet_id = w["id"] # get a new handle for the wallet handle = self.kcl.init_wallet_handle(wallet_id, wallet_pswd) # generate two accounts with kmd account_1 = self.kcl.generate_key(handle, False) account_2 = self.kcl.generate_key(handle, False) # get their private keys private_key_1 = self.kcl.export_key(handle, wallet_pswd, account_1) private_key_2 = self.kcl.export_key(handle, wallet_pswd, account_2) # get suggested parameters and fee gh = self.acl.versions()['genesis_hash_b64'] rnd = int(self.acl.status()['lastRound']) sp = transaction.SuggestedParams(0, rnd, rnd + 100, gh) # create multisig account and transaction msig = transaction.Multisig(1, 2, [account_1, account_2]) txn = transaction.PaymentTxn(msig.address(), sp, self.account_0, 1000) # check that the multisig account is valid msig.validate() # import multisig account msig_address = self.kcl.import_multisig(handle, msig) # export multisig account exported = self.kcl.export_multisig(handle, msig_address) self.assertEqual(len(exported.subsigs), 2) # create multisig transaction mtx = transaction.MultisigTransaction(txn, msig) # sign using kmd msig_1 = self.kcl.sign_multisig_transaction(handle, wallet_pswd, account_1, mtx) signed_kmd = self.kcl.sign_multisig_transaction( handle, wallet_pswd, account_2, msig_1) # sign offline mtx1 = transaction.MultisigTransaction(txn, msig) mtx1.sign(private_key_1) mtx2 = transaction.MultisigTransaction(txn, msig) mtx2.sign(private_key_2) signed_account = transaction.MultisigTransaction.merge([mtx1, mtx2]) # check that they are the same self.assertEqual(encoding.msgpack_encode(signed_account), encoding.msgpack_encode(signed_kmd)) # delete accounts del_1 = self.kcl.delete_key(handle, wallet_pswd, account_1) del_2 = self.kcl.delete_key(handle, wallet_pswd, account_2) del_3 = self.kcl.delete_multisig(handle, wallet_pswd, msig_address) self.assertTrue(del_1) self.assertTrue(del_2) self.assertTrue(del_3)