Purchase Transaction Type
This commit is contained in:
parent
3b88d2465d
commit
ab3b0134b5
3 changed files with 46 additions and 3 deletions
|
@ -21,7 +21,8 @@ class WalletDatabase(BaseDatabase):
|
||||||
claim_name text,
|
claim_name text,
|
||||||
is_claim boolean not null default 0,
|
is_claim boolean not null default 0,
|
||||||
is_update boolean not null default 0,
|
is_update boolean not null default 0,
|
||||||
is_support boolean not null default 0
|
is_support boolean not null default 0,
|
||||||
|
is_purchase boolean not null default 0
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ class WalletDatabase(BaseDatabase):
|
||||||
'is_claim': txo.script.is_claim_name,
|
'is_claim': txo.script.is_claim_name,
|
||||||
'is_update': txo.script.is_update_claim,
|
'is_update': txo.script.is_update_claim,
|
||||||
'is_support': txo.script.is_support_claim,
|
'is_support': txo.script.is_support_claim,
|
||||||
|
'is_purchase': txo.script.is_purchase_claim,
|
||||||
})
|
})
|
||||||
if txo.script.is_claim_involved:
|
if txo.script.is_claim_involved:
|
||||||
row['claim_id'] = txo.claim_id
|
row['claim_id'] = txo.claim_id
|
||||||
|
|
|
@ -12,6 +12,7 @@ class OutputScript(BaseOutputScript):
|
||||||
OP_CLAIM_NAME = 0xb5
|
OP_CLAIM_NAME = 0xb5
|
||||||
OP_SUPPORT_CLAIM = 0xb6
|
OP_SUPPORT_CLAIM = 0xb6
|
||||||
OP_UPDATE_CLAIM = 0xb7
|
OP_UPDATE_CLAIM = 0xb7
|
||||||
|
OP_PURCHASE_CLAIM = 0xb8
|
||||||
|
|
||||||
CLAIM_NAME_OPCODES = (
|
CLAIM_NAME_OPCODES = (
|
||||||
OP_CLAIM_NAME, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim'),
|
OP_CLAIM_NAME, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim'),
|
||||||
|
@ -46,13 +47,25 @@ class OutputScript(BaseOutputScript):
|
||||||
UPDATE_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
UPDATE_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
||||||
))
|
))
|
||||||
|
|
||||||
|
PURCHASE_CLAIM_OPCODES = (
|
||||||
|
OP_PURCHASE_CLAIM, PUSH_SINGLE('claim_id'), OP_2DROP
|
||||||
|
)
|
||||||
|
PURCHASE_CLAIM_PUBKEY = Template('purchase_claim+pay_pubkey_hash', (
|
||||||
|
PURCHASE_CLAIM_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes
|
||||||
|
))
|
||||||
|
PURCHASE_CLAIM_SCRIPT = Template('purchase_claim+pay_script_hash', (
|
||||||
|
PURCHASE_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
|
||||||
|
))
|
||||||
|
|
||||||
templates = BaseOutputScript.templates + [
|
templates = BaseOutputScript.templates + [
|
||||||
CLAIM_NAME_PUBKEY,
|
CLAIM_NAME_PUBKEY,
|
||||||
CLAIM_NAME_SCRIPT,
|
CLAIM_NAME_SCRIPT,
|
||||||
SUPPORT_CLAIM_PUBKEY,
|
SUPPORT_CLAIM_PUBKEY,
|
||||||
SUPPORT_CLAIM_SCRIPT,
|
SUPPORT_CLAIM_SCRIPT,
|
||||||
UPDATE_CLAIM_PUBKEY,
|
UPDATE_CLAIM_PUBKEY,
|
||||||
UPDATE_CLAIM_SCRIPT
|
UPDATE_CLAIM_SCRIPT,
|
||||||
|
PURCHASE_CLAIM_PUBKEY,
|
||||||
|
PURCHASE_CLAIM_SCRIPT
|
||||||
]
|
]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -63,6 +76,13 @@ class OutputScript(BaseOutputScript):
|
||||||
'pubkey_hash': pubkey_hash
|
'pubkey_hash': pubkey_hash
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def purchase_claim_pubkey_hash(cls, claim_id, pubkey_hash):
|
||||||
|
return cls(template=cls.PURCHASE_CLAIM_PUBKEY, values={
|
||||||
|
'claim_id': claim_id,
|
||||||
|
'pubkey_hash': pubkey_hash
|
||||||
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pay_update_claim_pubkey_hash(cls, claim_name, claim_id, claim, pubkey_hash):
|
def pay_update_claim_pubkey_hash(cls, claim_name, claim_id, claim, pubkey_hash):
|
||||||
return cls(template=cls.UPDATE_CLAIM_PUBKEY, values={
|
return cls(template=cls.UPDATE_CLAIM_PUBKEY, values={
|
||||||
|
@ -84,6 +104,13 @@ class OutputScript(BaseOutputScript):
|
||||||
def is_support_claim(self):
|
def is_support_claim(self):
|
||||||
return self.template.name.startswith('support_claim+')
|
return self.template.name.startswith('support_claim+')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_purchase_claim(self):
|
||||||
|
return self.template.name.startswith('purchase_claim+')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_claim_involved(self):
|
def is_claim_involved(self):
|
||||||
return self.is_claim_name or self.is_support_claim or self.is_update_claim
|
return any((
|
||||||
|
self.is_claim_name, self.is_support_claim,
|
||||||
|
self.is_update_claim, self.is_purchase_claim
|
||||||
|
))
|
||||||
|
|
|
@ -54,6 +54,11 @@ class Output(BaseOutput):
|
||||||
claim_name.encode(), claim, pubkey_hash)
|
claim_name.encode(), claim, pubkey_hash)
|
||||||
return cls(amount, script)
|
return cls(amount, script)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def purchase_claim_pubkey_hash(cls, amount: int, claim_id: str, pubkey_hash: bytes) -> 'Output':
|
||||||
|
script = cls.script_class.purchase_claim_pubkey_hash(unhexlify(claim_id)[::-1], pubkey_hash)
|
||||||
|
return cls(amount, script)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pay_update_claim_pubkey_hash(
|
def pay_update_claim_pubkey_hash(
|
||||||
cls, amount: int, claim_name: str, claim_id: str, claim: bytes, pubkey_hash: bytes) -> 'Output':
|
cls, amount: int, claim_name: str, claim_id: str, claim: bytes, pubkey_hash: bytes) -> 'Output':
|
||||||
|
@ -76,6 +81,15 @@ class Transaction(BaseTransaction):
|
||||||
)
|
)
|
||||||
return cls.create([], [claim_output], funding_accounts, change_account)
|
return cls.create([], [claim_output], funding_accounts, change_account)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def purchase(cls, claim: Output, amount: int, merchant_address: bytes,
|
||||||
|
funding_accounts: List[Account], change_account: Account):
|
||||||
|
ledger = cls.ensure_all_have_same_ledger(funding_accounts, change_account)
|
||||||
|
claim_output = Output.purchase_claim_pubkey_hash(
|
||||||
|
amount, claim.claim_id, ledger.address_to_hash160(merchant_address)
|
||||||
|
)
|
||||||
|
return cls.create([], [claim_output], funding_accounts, change_account)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update(cls, previous_claim: Output, meta: ClaimDict, amount: int, holding_address: bytes,
|
def update(cls, previous_claim: Output, meta: ClaimDict, amount: int, holding_address: bytes,
|
||||||
funding_accounts: List[Account], change_account: Account):
|
funding_accounts: List[Account], change_account: Account):
|
||||||
|
|
Loading…
Reference in a new issue