stubbed out buy/sell claim

This commit is contained in:
Lex Berezhny 2018-08-22 23:47:37 -04:00 committed by Jack Robison
parent 2238e1f802
commit afae649a9e
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 65 additions and 31 deletions

View file

@ -22,7 +22,8 @@ class WalletDatabase(BaseDatabase):
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 is_buy boolean not null default 0,
is_sell boolean not null default 0
); );
""" """
@ -39,7 +40,8 @@ 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, 'is_buy': txo.script.is_buy_claim,
'is_sell': txo.script.is_sell_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

View file

@ -1,5 +1,5 @@
from torba.basescript import BaseInputScript, BaseOutputScript, Template from torba.basescript import BaseInputScript, BaseOutputScript, Template
from torba.basescript import PUSH_SINGLE, OP_DROP, OP_2DROP from torba.basescript import PUSH_SINGLE, PUSH_INTEGER, OP_DROP, OP_2DROP, PUSH_SUBSCRIPT, OP_VERIFY
class InputScript(BaseInputScript): class InputScript(BaseInputScript):
@ -9,20 +9,26 @@ class InputScript(BaseInputScript):
class OutputScript(BaseOutputScript): class OutputScript(BaseOutputScript):
# lbry custom opcodes # lbry custom opcodes
# checks
OP_PRICECHECK = 0xb0 # checks that the BUY output is >= SELL price
# tx types
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 OP_SELL_CLAIM = 0xb8
OP_BUY_CLAIM = 0xb9
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'),
OP_2DROP, OP_DROP OP_2DROP, OP_DROP
) )
CLAIM_NAME_PUBKEY = Template('claim_name+pay_pubkey_hash', ( CLAIM_NAME_PUBKEY = Template('claim_name+pay_pubkey_hash', (
CLAIM_NAME_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes CLAIM_NAME_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes
)) ))
CLAIM_NAME_SCRIPT = Template('claim_name+pay_script_hash', ( CLAIM_NAME_SCRIPT = Template('claim_name+pay_script_hash', (
CLAIM_NAME_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes CLAIM_NAME_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
)) ))
SUPPORT_CLAIM_OPCODES = ( SUPPORT_CLAIM_OPCODES = (
@ -30,10 +36,10 @@ class OutputScript(BaseOutputScript):
OP_2DROP, OP_DROP OP_2DROP, OP_DROP
) )
SUPPORT_CLAIM_PUBKEY = Template('support_claim+pay_pubkey_hash', ( SUPPORT_CLAIM_PUBKEY = Template('support_claim+pay_pubkey_hash', (
SUPPORT_CLAIM_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes SUPPORT_CLAIM_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes
)) ))
SUPPORT_CLAIM_SCRIPT = Template('support_claim+pay_script_hash', ( SUPPORT_CLAIM_SCRIPT = Template('support_claim+pay_script_hash', (
SUPPORT_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes SUPPORT_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
)) ))
UPDATE_CLAIM_OPCODES = ( UPDATE_CLAIM_OPCODES = (
@ -41,21 +47,26 @@ class OutputScript(BaseOutputScript):
OP_2DROP, OP_2DROP OP_2DROP, OP_2DROP
) )
UPDATE_CLAIM_PUBKEY = Template('update_claim+pay_pubkey_hash', ( UPDATE_CLAIM_PUBKEY = Template('update_claim+pay_pubkey_hash', (
UPDATE_CLAIM_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes UPDATE_CLAIM_OPCODES + BaseOutputScript.PAY_PUBKEY_HASH.opcodes
)) ))
UPDATE_CLAIM_SCRIPT = Template('update_claim+pay_script_hash', ( UPDATE_CLAIM_SCRIPT = Template('update_claim+pay_script_hash', (
UPDATE_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes UPDATE_CLAIM_OPCODES + BaseOutputScript.PAY_SCRIPT_HASH.opcodes
)) ))
PURCHASE_CLAIM_OPCODES = ( SELL_SCRIPT = Template('sell_script', (
OP_PURCHASE_CLAIM, PUSH_SINGLE('claim_id'), OP_2DROP OP_VERIFY, OP_DROP, OP_DROP, OP_DROP, PUSH_INTEGER('price'), OP_PRICECHECK
)
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
)) ))
SELL_CLAIM = Template('sell_claim+pay_script_hash', (
OP_SELL_CLAIM, PUSH_SINGLE('claim_id'), PUSH_SUBSCRIPT('sell_script', SELL_SCRIPT),
PUSH_SUBSCRIPT('receive_script', BaseInputScript.REDEEM_SCRIPT), OP_2DROP, OP_2DROP
) + BaseOutputScript.PAY_SCRIPT_HASH.opcodes)
BUY_CLAIM = Template('buy_claim+pay_script_hash', (
OP_BUY_CLAIM, PUSH_SINGLE('sell_id'),
PUSH_SINGLE('claim_id'), PUSH_SINGLE('claim_version'),
PUSH_SINGLE('owner_pubkey_hash'), PUSH_SINGLE('negotiation_signature'),
OP_2DROP, OP_2DROP, OP_2DROP,
) + BaseOutputScript.PAY_SCRIPT_HASH.opcodes)
templates = BaseOutputScript.templates + [ templates = BaseOutputScript.templates + [
CLAIM_NAME_PUBKEY, CLAIM_NAME_PUBKEY,
@ -64,8 +75,8 @@ class OutputScript(BaseOutputScript):
SUPPORT_CLAIM_SCRIPT, SUPPORT_CLAIM_SCRIPT,
UPDATE_CLAIM_PUBKEY, UPDATE_CLAIM_PUBKEY,
UPDATE_CLAIM_SCRIPT, UPDATE_CLAIM_SCRIPT,
PURCHASE_CLAIM_PUBKEY, SELL_CLAIM, SELL_SCRIPT,
PURCHASE_CLAIM_SCRIPT BUY_CLAIM,
] ]
@classmethod @classmethod
@ -76,13 +87,6 @@ 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={
@ -92,6 +96,30 @@ class OutputScript(BaseOutputScript):
'pubkey_hash': pubkey_hash 'pubkey_hash': pubkey_hash
}) })
@classmethod
def sell_script(cls, price):
return cls(template=cls.SELL_SCRIPT, values={
'price': price,
})
@classmethod
def sell_claim(cls, claim_id, price, signatures, pubkeys):
return cls(template=cls.SELL_CLAIM, values={
'claim_id': claim_id,
'sell_script': OutputScript.sell_script(price),
'receive_script': InputScript.redeem_script(signatures, pubkeys)
})
@classmethod
def buy_claim(cls, sell_id, claim_id, claim_version, owner_pubkey_hash, negotiation_signature):
return cls(template=cls.BUY_CLAIM, values={
'sell_id': sell_id,
'claim_id': claim_id,
'claim_version': claim_version,
'owner_pubkey_hash': owner_pubkey_hash,
'negotiation_signature': negotiation_signature,
})
@property @property
def is_claim_name(self): def is_claim_name(self):
return self.template.name.startswith('claim_name+') return self.template.name.startswith('claim_name+')
@ -105,12 +133,16 @@ class OutputScript(BaseOutputScript):
return self.template.name.startswith('support_claim+') return self.template.name.startswith('support_claim+')
@property @property
def is_purchase_claim(self): def is_sell_claim(self):
return self.template.name.startswith('purchase_claim+') return self.template.name.startswith('sell_claim+')
@property
def is_buy_claim(self):
return self.template.name.startswith('buy_claim+')
@property @property
def is_claim_involved(self): def is_claim_involved(self):
return any(( return any((
self.is_claim_name, self.is_support_claim, self.is_claim_name, self.is_support_claim, self.is_update_claim,
self.is_update_claim, self.is_purchase_claim self.is_sell_claim, self.is_buy_claim
)) ))