-
Notifications
You must be signed in to change notification settings - Fork 37
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 ability to setFeePayer, add toString methods #83
Changes from all commits
9d0faf1
61b70c3
f64566b
96091d2
99e88f1
aa8e74b
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
package com.solana.core | ||
|
||
class AccountMeta(var publicKey: PublicKey, var isSigner: Boolean, var isWritable: Boolean) | ||
class AccountMeta(var publicKey: PublicKey, var isSigner: Boolean, var isWritable: Boolean) { | ||
override fun toString(): String { | ||
return "AccountMeta(publicKey: $publicKey, isSigner: $isSigner, isWritable: $isWritable)" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,10 @@ class Message { | |
) | ||
} | ||
|
||
override fun toString(): String { | ||
return "numRequiredSignatures: $numRequiredSignatures, numReadOnlySignedAccounts: $numReadonlySignedAccounts, numReadOnlyUnsignedAccounts: $numReadonlyUnsignedAccounts" | ||
} | ||
|
||
companion object { | ||
const val HEADER_LENGTH = 3 | ||
} | ||
|
@@ -39,7 +43,8 @@ class Message { | |
private var recentBlockhash: String? = null | ||
private val accountKeys: AccountKeysList = AccountKeysList() | ||
private val instructions: MutableList<TransactionInstruction> | ||
private var feePayer: Account? = null | ||
var feePayer: PublicKey? = null | ||
|
||
fun addInstruction(instruction: TransactionInstruction): Message { | ||
accountKeys.addAll(instruction.keys) | ||
accountKeys.add(AccountMeta(instruction.programId, false, false)) | ||
|
@@ -111,17 +116,17 @@ class Message { | |
return out.array() | ||
} | ||
|
||
fun setFeePayer(feePayer: Account?) { | ||
this.feePayer = feePayer | ||
} | ||
|
||
private fun getAccountKeys(): List<AccountMeta> { | ||
val keysList: MutableList<AccountMeta> = accountKeys.list | ||
val feePayerIndex = findAccountIndex(keysList, feePayer!!.publicKey) | ||
val newList: MutableList<AccountMeta> = ArrayList() | ||
val feePayerMeta = keysList[feePayerIndex] | ||
newList.add(AccountMeta(feePayerMeta.publicKey, true, true)) | ||
keysList.removeAt(feePayerIndex) | ||
try { | ||
val feePayerIndex = findAccountIndex(keysList, feePayer!!) | ||
val feePayerMeta = keysList[feePayerIndex] | ||
newList.add(AccountMeta(feePayerMeta.publicKey, true, true)) | ||
keysList.removeAt(feePayerIndex) | ||
} catch(e: RuntimeException) { // Fee payer not yet in list | ||
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 think it's better if 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. Another option is to implement a custom setter for FeePayer that adds the account to the array when it it set. My concern with that is it wouldn't be trivial to handle a situation like:
which would result in an extra account in the array unless some complex logic is implemented to decide if x can be safely removed in the setter. |
||
newList.add(AccountMeta(feePayer!!, true, true)) | ||
} | ||
newList.addAll(keysList) | ||
return newList | ||
} | ||
|
@@ -135,6 +140,15 @@ class Message { | |
throw RuntimeException("unable to find account index") | ||
} | ||
|
||
override fun toString(): 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. Thanks for this. |
||
return """Message( | ||
| header: not set, | ||
| accountKeys: [${accountKeys.list.joinToString()}], | ||
| recentBlockhash: $recentBlockhash, | ||
| instructions: [${instructions.joinToString()}] | ||
|)""".trimMargin() | ||
} | ||
|
||
companion object { | ||
private const val RECENT_BLOCK_HASH_LENGTH = 32 | ||
} | ||
|
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.
We need both getter and setter in order to check if we've already set a feePayer before applying the default.