forked from LBRYCommunity/lbry-sdk
stubbed out buy/sell claim
This commit is contained in:
parent
2238e1f802
commit
afae649a9e
2 changed files with 65 additions and 31 deletions
|
@ -22,7 +22,8 @@ class WalletDatabase(BaseDatabase):
|
|||
is_claim boolean not null default 0,
|
||||
is_update 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_update': txo.script.is_update_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:
|
||||
row['claim_id'] = txo.claim_id
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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):
|
||||
|
@ -9,10 +9,16 @@ class InputScript(BaseInputScript):
|
|||
class OutputScript(BaseOutputScript):
|
||||
|
||||
# lbry custom opcodes
|
||||
|
||||
# checks
|
||||
OP_PRICECHECK = 0xb0 # checks that the BUY output is >= SELL price
|
||||
|
||||
# tx types
|
||||
OP_CLAIM_NAME = 0xb5
|
||||
OP_SUPPORT_CLAIM = 0xb6
|
||||
OP_UPDATE_CLAIM = 0xb7
|
||||
OP_PURCHASE_CLAIM = 0xb8
|
||||
OP_SELL_CLAIM = 0xb8
|
||||
OP_BUY_CLAIM = 0xb9
|
||||
|
||||
CLAIM_NAME_OPCODES = (
|
||||
OP_CLAIM_NAME, PUSH_SINGLE('claim_name'), PUSH_SINGLE('claim'),
|
||||
|
@ -47,15 +53,20 @@ class OutputScript(BaseOutputScript):
|
|||
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
|
||||
SELL_SCRIPT = Template('sell_script', (
|
||||
OP_VERIFY, OP_DROP, OP_DROP, OP_DROP, PUSH_INTEGER('price'), OP_PRICECHECK
|
||||
))
|
||||
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 + [
|
||||
CLAIM_NAME_PUBKEY,
|
||||
|
@ -64,8 +75,8 @@ class OutputScript(BaseOutputScript):
|
|||
SUPPORT_CLAIM_SCRIPT,
|
||||
UPDATE_CLAIM_PUBKEY,
|
||||
UPDATE_CLAIM_SCRIPT,
|
||||
PURCHASE_CLAIM_PUBKEY,
|
||||
PURCHASE_CLAIM_SCRIPT
|
||||
SELL_CLAIM, SELL_SCRIPT,
|
||||
BUY_CLAIM,
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
@ -76,13 +87,6 @@ class OutputScript(BaseOutputScript):
|
|||
'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
|
||||
def pay_update_claim_pubkey_hash(cls, claim_name, claim_id, claim, pubkey_hash):
|
||||
return cls(template=cls.UPDATE_CLAIM_PUBKEY, values={
|
||||
|
@ -92,6 +96,30 @@ class OutputScript(BaseOutputScript):
|
|||
'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
|
||||
def is_claim_name(self):
|
||||
return self.template.name.startswith('claim_name+')
|
||||
|
@ -105,12 +133,16 @@ class OutputScript(BaseOutputScript):
|
|||
return self.template.name.startswith('support_claim+')
|
||||
|
||||
@property
|
||||
def is_purchase_claim(self):
|
||||
return self.template.name.startswith('purchase_claim+')
|
||||
def is_sell_claim(self):
|
||||
return self.template.name.startswith('sell_claim+')
|
||||
|
||||
@property
|
||||
def is_buy_claim(self):
|
||||
return self.template.name.startswith('buy_claim+')
|
||||
|
||||
@property
|
||||
def is_claim_involved(self):
|
||||
return any((
|
||||
self.is_claim_name, self.is_support_claim,
|
||||
self.is_update_claim, self.is_purchase_claim
|
||||
self.is_claim_name, self.is_support_claim, self.is_update_claim,
|
||||
self.is_sell_claim, self.is_buy_claim
|
||||
))
|
||||
|
|
Loading…
Reference in a new issue