-
Notifications
You must be signed in to change notification settings - Fork 3
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
sc-5933 Marshal transaction #99
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,21 +250,21 @@ func (Account) TableName() string { | |
// TODO: Add a field for the transaction payload marshaled as a string. | ||
type Transaction struct { | ||
gorm.Model | ||
TxID string `gorm:"not null"` | ||
Envelope string `gorm:"not null"` | ||
AccountID uint `gorm:"not null"` | ||
Account Account `gorm:"foreignKey:AccountID"` | ||
OriginatorID uint `gorm:"column:originator_id;not null"` | ||
Originator Identity `gorm:"foreignKey:OriginatorID"` | ||
BeneficiaryID uint `gorm:"column:beneficiary_id;not null"` | ||
Beneficiary Identity `gorm:"foreignKey:BeneficiaryID"` | ||
Amount decimal.Decimal `gorm:"type:numeric(15,2)"` | ||
Amount decimal.Decimal `gorm:"type:decimal(15,8)"` | ||
Debit bool `gorm:"not null"` | ||
State pb.TransactionState `gorm:"not null;default:0"` | ||
Timestamp time.Time `gorm:"not null"` | ||
NotBefore time.Time `gorm:"not null"` | ||
NotAfter time.Time `gorm:"not null"` | ||
Identity string `gorm:"not null"` | ||
Transaction string `gorm:"not null"` | ||
Comment on lines
266
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that we're using postgres we could consider making these JSON types rather than raw strings -- but only if it's easy to do. |
||
VaspID uint `gorm:"not null"` | ||
Vasp VASP `gorm:"foreignKey:VaspID"` | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -407,7 +407,7 @@ | |
"badnews@evilvasp.gg", | ||
3, | ||
"SendFull", | ||
"SyncRequire", | ||
"AsyncRepair", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this require us to re-migrate and update the documentation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation is already updated but we do need to run the migration at some point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good stopping point that we can tag this as v1.0 to test goreleaser and the container builds then run the migrations? The postgres migrations shouldn't result in any downtime for the rVASPs, so I think we can run them when we need to; but we should still do it at off-peak hours. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do that whenever, I don't have any more rVASP work planned for the current sprint. |
||
{ | ||
"natural_person": { | ||
"name": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,8 +524,7 @@ func (s *Server) respondAsync(peer *peers.Peer, payload *protocol.Payload, ident | |
switch xfer.State { | ||
case pb.TransactionState_AWAITING: | ||
// Fill the transaction with a new TxID to continue the handshake | ||
xfer.TxID = uuid.New().String() | ||
transaction.Txid = xfer.TxID | ||
transaction.Txid = uuid.New().String() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch - CipherTrace has been reporting an issue where the rVASP returns an incorrect "receipt ID" than the one it was sent. I wonder if this is related. Note that they claim that receipt ID == envelope ID, but I'm not sure about that terminology. CC @DanielSollis |
||
if payload, err = createTransferPayload(identity, transaction); err != nil { | ||
log.Error().Err(err).Msg("could not create transfer payload") | ||
return nil, protocol.Errorf(protocol.InternalError, "could not create transfer payload: %s", err) | ||
|
@@ -578,6 +577,13 @@ func (s *Server) respondAsync(peer *peers.Peer, payload *protocol.Payload, ident | |
} | ||
xfer.Identity = string(data) | ||
|
||
// Update the transaction with the new generic.Transaction | ||
if data, err = json.Marshal(transaction); err != nil { | ||
log.Error().Err(err).Msg("could not marshal generic.Transaction") | ||
return nil, status.Errorf(codes.Internal, "could not marshal generic.Transaction: %s", err) | ||
} | ||
xfer.Transaction = string(data) | ||
|
||
// Update the Transaction in the database with the pending timestamps | ||
if xfer.NotBefore, err = time.Parse(time.RFC3339, pending.ReplyNotBefore); err != nil { | ||
log.Error().Err(err).Msg("TRISA protocol error: could not parse ReplyNotBefore timestamp") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,121 @@ | ||
#!/bin/bash | ||
# TODO: check codes | ||
|
||
if [ "$1" == "--local" ]; then | ||
ALICE_ENDPOINT=localhost:5434 | ||
BOB_ENDPOINT=localhost:6434 | ||
else | ||
ALICE_ENDPOINT=admin.alice.vaspbot.net:443 | ||
BOB_ENDPOINT=admin.bob.vaspbot.net:443 | ||
fi | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've discovered that this script is really useful for local testing as well, thanks for adding it! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Glad it's helpful! |
||
|
||
# Send from Alice to Bob | ||
# Partial Sync Repair: success expected | ||
echo "Alice --> Bob Partial Sync Repair" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 1ASkqdo1hvydosVRvRv2j6eNnWpWLHucMX -d 0.0001 \ | ||
-b 18nxAxBktHZDrMoJ3N2fk9imLX8xNnYbNh | ||
|
||
# Partial Sync Require: rejection expected | ||
echo "Alice --> Bob Partial Sync Require" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 1ASkqdo1hvydosVRvRv2j6eNnWpWLHucMX -d 0.0002 \ | ||
-b 1LgtLYkpaXhHDu1Ngh7x9fcBs5KuThbSzw | ||
|
||
# Full Sync Repair: success expected | ||
echo "Alice --> Bob Full Sync Repair" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 1MRCxvEpBoY8qajrmNTSrcfXSZ2wsrGeha -d 0.0003 \ | ||
-b 18nxAxBktHZDrMoJ3N2fk9imLX8xNnYbNh | ||
|
||
# Full Sync Require: success expected | ||
echo "Alice --> Bob Full Sync Require" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 14HmBSwec8XrcWge9Zi1ZngNia64u3Wd2v -d 0.0004 \ | ||
-b 1LgtLYkpaXhHDu1Ngh7x9fcBs5KuThbSzw | ||
|
||
# Partial Async Repair: success expected | ||
# TODO: how to test getting a message back? | ||
echo "Alice --> Bob Partial Async Repair" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 1ASkqdo1hvydosVRvRv2j6eNnWpWLHucMX -d 0.0005 \ | ||
-b 14WU745djqecaJ1gmtWQGeMCFim1W5MNp3 | ||
|
||
# Partial Async Reject: rejection expected | ||
echo "Alice --> Bob Partial Async Reject" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 1ASkqdo1hvydosVRvRv2j6eNnWpWLHucMX -d 0.0006 \ | ||
-b 1Hzej6a2VG7C8iCAD5DAdN72cZH5THSMt9 | ||
|
||
# Full Async Repair: success expected | ||
echo "Alice --> Bob Full Async Repair" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 1MRCxvEpBoY8qajrmNTSrcfXSZ2wsrGeha -d 0.0007 \ | ||
-b 14WU745djqecaJ1gmtWQGeMCFim1W5MNp3 | ||
|
||
# Full Async Require: reject expected | ||
echo "Alice --> Bob Full Async Reject" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 14HmBSwec8XrcWge9Zi1ZngNia64u3Wd2v -d 0.0008 \ | ||
-b 1Hzej6a2VG7C8iCAD5DAdN72cZH5THSMt9 | ||
|
||
# Send Error: rejection expected. | ||
echo "Alice --> Bob Send Error" | ||
rvasp transfer -e admin.alice.vaspbot.net:443 \ | ||
rvasp transfer -e $ALICE_ENDPOINT \ | ||
-a 19nFejdNSUhzkAAdwAvP3wc53o8dL326QQ -d 0.0009 \ | ||
-b 1Hzej6a2VG7C8iCAD5DAdN72cZH5THSMt9 | ||
|
||
# Send from Bob to Alice | ||
# Partial Sync Repair: success expected | ||
echo "Bob --> Alice Partial Sync Repair" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 18nxAxBktHZDrMoJ3N2fk9imLX8xNnYbNh -d 0.00010 \ | ||
-b 1ASkqdo1hvydosVRvRv2j6eNnWpWLHucMX | ||
|
||
# Partial Sync Require: rejection expected | ||
echo "Bob --> Alice Partial Sync Require" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 18nxAxBktHZDrMoJ3N2fk9imLX8xNnYbNh -d 0.00011 \ | ||
-b 1MRCxvEpBoY8qajrmNTSrcfXSZ2wsrGeha | ||
|
||
# Full Sync Repair: success expected | ||
echo "Bob --> Alice Full Sync Repair" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 1LgtLYkpaXhHDu1Ngh7x9fcBs5KuThbSzw -d 0.00012 \ | ||
-b 1ASkqdo1hvydosVRvRv2j6eNnWpWLHucMX | ||
|
||
# Full Sync Require: success expected | ||
echo "Bob --> Alice Full Sync Require" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 14WU745djqecaJ1gmtWQGeMCFim1W5MNp3 -d 0.00013 \ | ||
-b 1MRCxvEpBoY8qajrmNTSrcfXSZ2wsrGeha | ||
|
||
# Partial Async Repair: success expected | ||
echo "Bob --> Alice Partial Async Repair" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 18nxAxBktHZDrMoJ3N2fk9imLX8xNnYbNh -d 0.00014 \ | ||
-b 14HmBSwec8XrcWge9Zi1ZngNia64u3Wd2v | ||
|
||
# Partial Async Require: rejection expected | ||
echo "Bob --> Alice Partial Async Reject" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 18nxAxBktHZDrMoJ3N2fk9imLX8xNnYbNh -d 0.00015 \ | ||
-b 19nFejdNSUhzkAAdwAvP3wc53o8dL326QQ | ||
|
||
# Full Async Repair: success expected | ||
echo "Bob --> Alice Full Async Repair" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 1LgtLYkpaXhHDu1Ngh7x9fcBs5KuThbSzw -d 0.00016 \ | ||
-b 14HmBSwec8XrcWge9Zi1ZngNia64u3Wd2v | ||
|
||
# Full Async Require: rejection expected | ||
echo "Bob --> Alice Full Async Reject" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 14WU745djqecaJ1gmtWQGeMCFim1W5MNp3 -d 0.00017 \ | ||
-b 19nFejdNSUhzkAAdwAvP3wc53o8dL326QQ | ||
|
||
# Send Error: rejection expected. | ||
echo "Bob --> Alice Send Error" | ||
rvasp transfer -e admin.bob.vaspbot.net:443 \ | ||
rvasp transfer -e $BOB_ENDPOINT \ | ||
-a 1Hzej6a2VG7C8iCAD5DAdN72cZH5THSMt9 -d 0.00018 \ | ||
-b 14HmBSwec8XrcWge9Zi1ZngNia64u3Wd2v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid truncation in the database for small valued transfers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe, you're right
numeric(15,2)
is for real money that has cents and not partial cents but we definitely need more precision for bitcoin transactions that can have a large fraction of a coin! Definitely a bit of bias we added when I first developed this model!