Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reissuable Token AR #52

Merged
merged 15 commits into from
May 27, 2021
3 changes: 2 additions & 1 deletion lib/glueby/contract/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ def to_payload
def self.parse_from_payload(payload)
color_id, script_pubkey = payload.unpack('a33a*')
color_id = Tapyrus::Color::ColorIdentifier.parse_from_payload(color_id)
if color_id.type == Tapyrus::Color::TokenTypes::REISSUABLE && !script_pubkey.empty?
if color_id.type == Tapyrus::Color::TokenTypes::REISSUABLE
raise ArgumentError, 'script_pubkey is not nil.' unless !script_pubkey.empty?
rantan marked this conversation as resolved.
Show resolved Hide resolved
rantan marked this conversation as resolved.
Show resolved Hide resolved
script_pubkey = Tapyrus::Script.parse_from_payload(script_pubkey)
Glueby::Contract::AR::ReissuableToken.create!(color_id: color_id.to_hex, script_pubkey: script_pubkey.to_hex)
end
Expand Down
4 changes: 2 additions & 2 deletions spec/glueby/contract/token_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
context 'with no script pubkey' do
let(:token) { Glueby::Contract::Token.parse_from_payload('c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3'.htb) }

it { is_expected.to eq 'c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3' }
it { expect { subject }.to raise_error(ArgumentError, 'script_pubkey is not nil.') }
end
end

Expand All @@ -306,7 +306,7 @@
let(:token) { Glueby::Contract::Token.parse_from_payload('c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3'.htb) }

it do
expect(subject).to eq 'c150ad685ec8638543b2356cb1071cf834fb1c84f5fa3a71699c3ed7167dfcdbb3'
expect{ subject } .to raise_error(ArgumentError, 'script_pubkey is not nil.')
expect(Glueby::Contract::AR::ReissuableToken.count).to eq 0
end
end
Expand Down