def sign_transaction(self, tx: Transaction, signer: Account): tx_hash = tx.hash256() sig_data = signer.generate_signature(tx_hash, signer.get_signature_scheme()) sig = [Sig([signer.get_public_key()], 1, [sig_data])] tx.sigs = sig return tx
from ontology.common.address import Address from ontology.account.account import Account from ontology.utils.util import get_random_str from ontology.crypto.signature_scheme import SignatureScheme from ontology.smart_contract.native_contract.asset import Asset sdk = OntologySdk() rpc_address = "http://polaris3.ont.io:20336" sdk.rpc.set_address(rpc_address) private_key = "523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f" private_key2 = "75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf" private_key3 = "1383ed1fe570b6673351f1a30a66b21204918ef8f673e864769fa2a653401114" acc = Account(private_key, SignatureScheme.SHA256withECDSA) acc2 = Account(private_key2, SignatureScheme.SHA256withECDSA) acc3 = Account(private_key3, SignatureScheme.SHA256withECDSA) pubkeys = [acc.get_public_key(), acc2.get_public_key(), acc3.get_public_key()] multi_addr = Address.address_from_multi_pub_keys(2, pubkeys) class TestRpcClient(unittest.TestCase): def test_get_version(self): version = sdk.rpc.get_version() self.assertEqual("v1.0.3-rc", version) def test_get_node_count(self): count = sdk.rpc.get_node_count() self.assertGreaterEqual(count, 0) def test_get_gas_price(self): price = sdk.rpc.get_gas_price() self.assertGreater(price, 0)
from ontology.wallet.wallet import WalletData rpc_address = "http://polaris3.ont.io:20336" sdk = OntologySdk() sdk.rpc.set_address(rpc_address) private_key1 = "523c5fcf74823831756f0bcb3634234f10b3beb1c05595058534577752ad2d9f" private_key2 = "75de8489fcb2dcaf2ef3cd607feffde18789de7da129b5e97c81e001793cb7cf" private_key3 = "1383ed1fe570b6673351f1a30a66b21204918ef8f673e864769fa2a653401114" acct1 = Account(private_key1, SignatureScheme.SHA256withECDSA) acct2 = Account(private_key2, SignatureScheme.SHA256withECDSA) acct3 = Account(private_key3, SignatureScheme.SHA256withECDSA) pub_keys = [ acct1.get_public_key(), acct2.get_public_key(), acct3.get_public_key() ] multi_address = Address.address_from_multi_pub_keys(2, pub_keys) class TestOntologySdk(TestCase): def test_open_wallet(self): path = os.path.join(os.getcwd(), 'test.json') wallet = sdk.open_wallet(path) self.assertTrue(wallet, isinstance(wallet, WalletData)) os.remove(path) def test_add_multi_sign_transaction(self): self.assertEqual(multi_address.b58encode(),