Skip to content

Commit

Permalink
Add NFToken, Clawback & AMM (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 authored Jun 6, 2024
2 parents 6cbedc6 + 3839eea commit 82eccc6
Show file tree
Hide file tree
Showing 1,463 changed files with 1,261 additions and 209 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ APPNAME = XRP

APPVERSION_M=2
APPVERSION_N=4
APPVERSION_P=0
APPVERSION_P=1
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

# Application source files
Expand Down
159 changes: 84 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,27 @@ and the examples below.
The XRP wallet app comes with the following features:

- Support for all transaction types:
- AMMBid
- AMMCreate
- AMMDelete
- AMMDeposit
- AMMVote
- AMMWithdrawal
- AccountSet
- AccountDelete
- CheckCancel
- CheckCash
- CheckCreate
- Clawback
- DepositPreauth
- EscrowCancel
- EscrowCreate
- EscrowFinish
- NFTokenAcceptOffer
- NFTokenBurn
- NFTokenCancelOffer
- NFTokenCreateOffer
- NFTokenMint
- OfferCancel
- OfferCreate
- Payment
Expand All @@ -36,6 +48,8 @@ The XRP wallet app comes with the following features:
- PaymentChannelFund
- SetRegularKey
- SignerListSet
- TicketCancel
- TicketCreate
- TrustSet
- Support for all transaction common fields such as memos
- Support for issued assets such as SOLO, stocks and ETFs
Expand Down Expand Up @@ -93,50 +107,49 @@ An example of a basic payment transaction using this library is shown below:
import Transport from "@ledgerhq/hw-transport-node-hid";
// import Transport from "@ledgerhq/hw-transport-u2f"; // for browser
import Xrp from "@ledgerhq/hw-app-xrp";
import { encode } from 'ripple-binary-codec';
import { encode } from "ripple-binary-codec";

function establishConnection() {
return Transport.create()
.then(transport => new Xrp(transport));
return Transport.create().then((transport) => new Xrp(transport));
}

function fetchAddress(xrp) {
return xrp.getAddress("44'/144'/0'/0/0").then(deviceData => {
return {
xrp,
address: deviceData.address,
publicKey: deviceData.publicKey.toUpperCase()
}
});
return xrp.getAddress("44'/144'/0'/0/0").then((deviceData) => {
return {
xrp,
address: deviceData.address,
publicKey: deviceData.publicKey.toUpperCase(),
};
});
}

function signTransaction(context, transaction) {
const preparedTransaction = {
Account: context.address,
SigningPubKey: context.publicKey,
...transaction
};
const preparedTransaction = {
Account: context.address,
SigningPubKey: context.publicKey,
...transaction,
};

const transactionBlob = encode(preparedTransaction);
const transactionBlob = encode(preparedTransaction);

console.log('Sending transaction to device for approval...');
return context.xrp.signTransaction("44'/144'/0'/0/0", transactionBlob);
console.log("Sending transaction to device for approval...");
return context.xrp.signTransaction("44'/144'/0'/0/0", transactionBlob);
}

const transactionJSON = {
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 57,
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 57,
};

establishConnection()
.then(xrp => fetchAddress(xrp))
.then(context => signTransaction(context, transactionJSON))
.then(signature => console.log(`Signature: ${signature}`))
.catch(e => console.log(`An error occurred (${e.message})`));
.then((xrp) => fetchAddress(xrp))
.then((context) => signTransaction(context, transactionJSON))
.then((signature) => console.log(`Signature: ${signature}`))
.catch((e) => console.log(`An error occurred (${e.message})`));
```

### Advanced Usage
Expand All @@ -151,64 +164,60 @@ with a signature of the Ledger device is shown below (uses imports and functions

```javascript
const transactionJSON = {
Account: "r4PCuDkjuV2e23xVP8ChkVxo1aG2Ufpkjb",
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 47,
SigningPubKey: "" // Must be blank
Account: "r4PCuDkjuV2e23xVP8ChkVxo1aG2Ufpkjb",
TransactionType: "Payment",
Destination: "rTooLkitCksh5mQa67eaa2JaWHDBnHkpy",
Amount: "1000000",
Fee: "15",
Flags: 2147483648,
Sequence: 47,
SigningPubKey: "", // Must be blank
};

// Sourced externally from other signing parties, replace "..." with actual values.
const otherSigners = [
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "..."
}
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "...",
},
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "..."
}
}
},
{
Signer: {
Account: "...",
SigningPubKey: "...",
TxnSignature: "...",
},
},
];

function retrieveSignerData(transaction) {
return establishConnection()
.then(xrp => fetchAddress(xrp))
.then(context => {
return signTransaction(context, transaction)
.then(signature => {
return {
Signer: {
Account: context.account,
SigningPubKey: context.publicKey,
TxnSignature: signature.toUpperCase()
}
}
});
})
.catch(e => console.log(`An error occurred (${e.message})`));
return establishConnection()
.then((xrp) => fetchAddress(xrp))
.then((context) => {
return signTransaction(context, transaction).then((signature) => {
return {
Signer: {
Account: context.account,
SigningPubKey: context.publicKey,
TxnSignature: signature.toUpperCase(),
},
};
});
})
.catch((e) => console.log(`An error occurred (${e.message})`));
}

retrieveSignerData(transactionJSON)
.then(signer => {
return {
...transactionJSON,
Signers: [
...otherSigners,
signer
]
}
})
.then(transaction => console.log(transaction))
.catch(e => console.log(`An error occurred (${e.message})`));
.then((signer) => {
return {
...transactionJSON,
Signers: [...otherSigners, signer],
};
})
.then((transaction) => console.log(transaction))
.catch((e) => console.log(`An error occurred (${e.message})`));
```

### Additional Notes
Expand Down
2 changes: 1 addition & 1 deletion src/xrp/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static int format_xrp(uint64_t amount, field_value_t *dst) {
return 0;
}

static bool is_all_zeros(const uint8_t *data, uint8_t length) {
bool is_all_zeros(const uint8_t *data, uint8_t length) {
for (size_t i = 0; i < length; ++i) {
if (data[i] != 0) {
return false;
Expand Down
1 change: 1 addition & 0 deletions src/xrp/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void amount_formatter(field_t* field, field_value_t* dst);
void currency_formatter(field_t* field, field_value_t* dst);

bool has_non_standard_currency(field_t* field);
bool is_all_zeros(const uint8_t *data, uint8_t length);

#define XRP_AMOUNT_LEN 8
#define ISSUED_CURRENCY_LEN 48
Expand Down
Loading

0 comments on commit 82eccc6

Please sign in to comment.