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 asset flag to rvasps #124

Merged
merged 3 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/rvasp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func main() {
Name: "d, amount",
Usage: "the amount to transfer to the beneficiary",
},
&cli.StringFlag{
Name: "t, asset-type",
Usage: "the type of virtual asset",
Value: "bitcoin",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the asset type supposed to be a shorthand (e.g. BTC, USD, ETH)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The transfer requests I looked at have the whole word. I don't know if the TRISA whitepaper makes a recommendation, that would be something to check into.

},
&cli.StringFlag{
Name: "B, beneficiary-vasp",
Usage: "the common name or vasp directory searchable name of the beneficiary vasp",
Expand Down Expand Up @@ -343,6 +348,7 @@ func transfer(c *cli.Context) (err error) {
Beneficiary: c.String("beneficiary"),
BeneficiaryVasp: c.String("beneficiary-vasp"),
Amount: float32(c.Float64("amount")),
AssetType: c.String("asset-type"),
ExternalDemo: c.Bool("external-demo"),
}

Expand Down
931 changes: 38 additions & 893 deletions lib/python/rvaspy/rvaspy/api_pb2.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/python/rvaspy/rvaspy/api_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""Client and server classes corresponding to protobuf-defined services."""
import grpc

import rvaspy.api_pb2 as api__pb2
import api_pb2 as api__pb2


class TRISADemoStub(object):
Expand Down
7 changes: 4 additions & 3 deletions pkg/rvasp/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ type Transaction struct {
BeneficiaryID uint `gorm:"column:beneficiary_id;not null"`
Beneficiary Identity `gorm:"foreignKey:BeneficiaryID"`
Amount decimal.Decimal `gorm:"type:decimal(15,8)"`
AssetType string `gorm:"not null"`
Debit bool `gorm:"not null"`
State pb.TransactionState `gorm:"not null;default:0"`
StateString string `gorm:"column:state_string;not null"`
Expand All @@ -284,7 +285,7 @@ func (t *Transaction) SetState(state pb.TransactionState) {

// Identity holds raw data for an originator or a beneficiary that was sent as
// part of the transaction process. This should not be stored in the wallet since the
// wallet is a representation of the local VASPs knowledge about customers and bercause
// wallet is a representation of the local VASPs knowledge about customers and because
// the identity information could change between transactions. This intermediate table
// is designed to more closely mimic data storage as part of a blockchain transaction.
type Identity struct {
Expand All @@ -301,7 +302,7 @@ func (Identity) TableName() string {
return "identities"
}

// BalanceFloat converts the balance decmial into an exact two precision float32 for
// BalanceFloat converts the balance decimal into an exact two precision float32 for
// use with the protocol buffers.
func (a Account) BalanceFloat() float32 {
bal, _ := a.Balance.Truncate(2).Float64()
Expand Down Expand Up @@ -364,7 +365,7 @@ func (t Transaction) GetBeneficiary(db *DB) (identity *Identity, err error) {
return identity, nil
}

// AmountFloat converts the amount decmial into an exact two precision float32 for
// AmountFloat converts the amount decimal into an exact two precision float32 for
// use with the protocol buffers.
func (t Transaction) AmountFloat() float32 {
bal, _ := t.Amount.Truncate(2).Float64()
Expand Down
240 changes: 125 additions & 115 deletions pkg/rvasp/pb/v1/api.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/rvasp/pb/v1/api_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pkg/rvasp/rvasp.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func (s *Server) Transfer(ctx context.Context, req *pb.TransferRequest) (reply *
}
xfer.Account = account
xfer.Amount = decimal.NewFromFloat32(req.Amount)
xfer.AssetType = req.AssetType
xfer.Debit = true

// Run the scenario for the wallet's configured policy
Expand Down Expand Up @@ -314,7 +315,7 @@ func (s *Server) sendTransfer(xfer *db.Transaction, beneficiary *db.Wallet, part
// Fetch the signing key
var signKey *rsa.PublicKey
if signKey, err = s.fetchSigningKey(peer); err != nil {
log.Warn().Err(err).Msg("could not fetch signing key from benficiary peer")
log.Warn().Err(err).Msg("could not fetch signing key from beneficiary peer")
return status.Errorf(codes.FailedPrecondition, "could not fetch signing key from beneficiary peer: %s", err)
}

Expand All @@ -336,6 +337,7 @@ func (s *Server) sendTransfer(xfer *db.Transaction, beneficiary *db.Wallet, part
Originator: xfer.Account.WalletAddress,
Beneficiary: beneficiary.Address,
Network: "TestNet",
AssetType: xfer.AssetType,
Timestamp: xfer.Timestamp.Format(time.RFC3339),
}

Expand Down Expand Up @@ -593,7 +595,7 @@ func (s *Server) respondAsync(peer *peers.Peer, payload *protocol.Payload, ident
}
xfer.SetState(pb.TransactionState_COMPLETED)
default:
log.Error().Str("state", xfer.State.String()).Msg("unepected transaction state")
log.Error().Str("state", xfer.State.String()).Msg("unexpected transaction state")
return nil, protocol.Errorf(protocol.ComplianceCheckFail, "unexpected transaction state: %s", xfer.State.String())
}

Expand Down Expand Up @@ -924,7 +926,7 @@ func (s *Server) handleTransaction(client string, req *pb.Command) (err error) {
if signKey, err = peer.ExchangeKeys(true); err != nil {
log.Error().Err(err).Msg("could not exchange keys with remote peer")
return s.updates.SendTransferError(client, req.Id,
pb.Errorf(pb.ErrInternal, "could not exchange keyrs with remote peer"),
pb.Errorf(pb.ErrInternal, "could not exchange keys with remote peer"),
)
}

Expand Down Expand Up @@ -1107,7 +1109,7 @@ func (s *Server) handleTransaction(client string, req *pb.Command) (err error) {
)
}

message = fmt.Sprintf("transaction %04d complete: %s transfered from %s to %s", xfer.ID, xfer.Amount.String(), xfer.Originator.WalletAddress, xfer.Beneficiary.WalletAddress)
message = fmt.Sprintf("transaction %04d complete: %s transferred from %s to %s", xfer.ID, xfer.Amount.String(), xfer.Originator.WalletAddress, xfer.Beneficiary.WalletAddress)
s.updates.Broadcast(req.Id, message, pb.MessageCategory_BLOCKCHAIN)
time.Sleep(time.Duration(rand.Int63n(1000)) * time.Millisecond)

Expand Down
3 changes: 2 additions & 1 deletion proto/rvasp/v1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ message Transaction {
Account beneficiary = 2; // Target described by wallet address or email of beneficiary
float amount = 3; // amount of the transaction
string timestamp = 4; // timestamp of completion on the account provider side
string envelope_id = 5; // envelope ID from TRISA (not included between TRISA peers)
string envelope_id = 5; // envelope ID from TRISA (not included between TRISA peers)
string identity = 6; // identity payload from TRISA (not included between TRISA peers)
TransactionState state = 7; // state of the transaction
}
Expand All @@ -70,6 +70,7 @@ message TransferRequest {
string account = 1; // email address or crypto wallet of the account to debit
string beneficiary = 2; // email address or crypto wallet to look up beneficiary with
float amount = 3; // amount to transfer to the beneficiary (will be truncated to 2 decimal points)
string asset_type = 8; // the type of virtual asset for multi-asset chains (optional)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to the bottom for clarity? Also, if we're saying it's an optional field here, should it not have a default value in the CLI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it after amount to keep it in line with the order in the trisa repo protobuf definition but I'll move it to the bottom. Good catch on the optional tag, I added that before I put the default value in the CLI.

string originating_vasp = 4; // common name of the originating VASP for demo UI error handling (optional)
string beneficiary_vasp = 5; // common name of the beneficiary VASP for demo UI error handling or external demo lookup (optional if external_demo is false)
bool check_beneficiary = 6; // if set, confirm that the beneficiary wallet belongs to the beneficiary VASP (optional)
Expand Down