How to get Fee Payer of a transaction? from TransactionResponse object - web3js

I am trying to make a small public script to fetch the initial minter of a token or a list of tokens.
The easiest way is to fetch the transaction that matches with the correct program id and get the fee payer because, in 99.99% of the cases, the fee payer is the minter itself.
I am trying to get the fee payer from a TransactionResponse object.
I can see that transaction.transaction.message.accountKeys[0] gives the fee payer but I couldn't find any resource to verify that the first account in accountKeys array is always the fee payer.
Is this way safe? If not, is there any other convenient way to fetch the fee payer of a transaction?

The payer is always the first account referenced, and the first signature is by the fee payer.
Here's a reference in the message code:
In the `Message` structure, the first account is always the fee-payer,
Excerpted from https://github.com/solana-labs/solana/blob/c419845cfeb1c7ab9ca959de66e90b9dacbc25b7/sdk/program/src/message/legacy.rs#L90
You can follow along the (slightly complicated) logic in JS: https://github.com/solana-labs/solana/blob/c419845cfeb1c7ab9ca959de66e90b9dacbc25b7/web3.js/src/transaction.ts#L415

Related

How to create the LINK in data vault without having strong relationship keys (Foreign Keys)?

Our sales representatives call Leads to propose services. Leads are stored in Crm with attributes: LeadId, PrimaryContactNumber, SecondaryContactNumber. All calls are done via Teams and recorded. Calls could be extracted via Microsoft Graph Api and have attributes: CallId, UserId, CalleeNumber, CallerNumber, Duration. Users have these attributes: UserId, Username, Email. How can I generate LINK (relation between User, Lead) using data vault modeling when foreign keys are not known? I thought my design should look like this: User(hub)-Call(link)-Lead(hub), but my call has only userId, leadId could only be inferred from one of the Lead attributes(PrimaryContactNumber or SecondaryContactNumber) What is the best solution to this problem? Or should I model Call as a hub aswell and perform filter when loading data to datamart?
A call is not a business entities, it's rather a relation between a sales person and a lead. So, your first thought is right.
To answers your question, you might want take a look at the zero/ghost records concept. http://roelantvos.com/blog/unknown-keys-zero-keys-or-ghost-keys-in-hubs-for-dv2-0/
Basically, add a "Unknown" entry in your Lead(Hub). Then, when you generate the link and the Lead is not known, simply link it to the unknown entities. Make sure you add a satellite to you link, so you can track the period it was unknown, and when it is known.

How To Summarize A Rollup Relationship That Cross References A Custom Object?

We are trying to implement a University system for students, faculty, and staff to be able to better manage course registrations as well as other enrollment activities.
Consider the following problem: When a student registers for a course, the course needs to get added to the students bill as a billing line item. The bill needs to have a total price of all the courses that have been registered for that particular student. Note: We've tried to keep the process manual in order to simplify the requirements.
We have identified 4 custom objects and some important fields:
Courses - Course Name:(Primary Key), Course Size:(Number), Course Price:(Currency), Start Date:(Date), End Date:(Date), Students Enrolled:(Rollup Count)
Course Registrations - Course Registration Number:(Primary Key), Course List:(Master-Detail), Student:(Lookup), Course Price:(Formula), Course Credits:(Formula)
Billing Line Item - Billing Line Item Number:(Primary Key), Course Registration:(Master-Detail), Bill:(Master-Detail), Course Price:(Formula)
Bill - Bill Name:(Primary Key), Student:(Lookup)
We know in order to summarize the total of all course prices, we need to make the Billing Line Item the detail object and the Bill the master object. We want to perform a Rollup Summary on all the Billing Line Item prices.
We've also made the Billing Line Item the detail object and the Course Registration a master object. This is because without a Course Registration, there is no need for a Billing Line Item to exist. Also the Course Registration has the Course Price via a formula which needs to be used in order to summarize the total cost of all courses.
I've seen online that you are unable to summarize a cross-reference object. We are getting confused as to how we should summarize all the prices associated with each course. Any help would be greatly appreciated. We can provide screenshots if requested!
I don't think the reference to course price should be a formula. Next year you'll change prices and it'll retroactively screw your past invoices up? (and you wouldn't even have field history tracking on the formula field, only on the Course. So if you don't know where to look it'll be as if it always was this price)
Make it a normal editable Number field (although Currency type would be better) and use workflow / "early" flow / process builder or code to populate the list price on save. You don't lose anything (as you create new line item now you also don't see the price until you save, formula field doesn't show up on "new", right?). This normal field will already be rollup-able but you can spice things up by adding discount % or differentiate between list price, sales price... Look how much stuff is on built-in OpportunityLineItem
If you feel really fancy - you can include something that on change of Course's list price would cascade down to all registrations and billing items where status = Open(?) and update the list price...

Database design for Workflow based system

I am designing a database for a sales company having a complex workflow. The flow starts at Sales Officer, then go to Team Lead and finally Manager. Before approving a proposal, manager will send it to the Division Business Analyst. After getting remarks from dba, he may send the proposal back to sales officer for modification in the proposal. The manager may also reject the proposal. If satisfied, manager will forward it to Director, Sales. The tables designed so far as follows:-
Table: ProposalBasicData
Id, Title, ProposalDate, Scope, Objective
Table: ProposalState
Id, Name
(Values - Forwarded , Approved , Returned , Rejected)
Table: UserType
Id, Name
(Values - SalesOfficer, TeamLead, Manager , DBA, DirectorSales)
Table: WorkFlow
Id, StartUserType, NextUserType, StateId, IsActive
Table: RequestAction
Id, ProposalId, WorkFlowId, UserId, ActionDate
Please suggest regarding the design.
There are many questions raised by such problems. Ex:
in your tables, Workflow defines transitions from state to state as changing the assignment from one user to the next.
this can be an issue. Lets say the user is sick, leaving, on vacation, ... Then your flow is blocked.
It does not allow for the group concept either.
others (like I) would define a transitions table. StartState, NextState.
The workflow would be a list of transitions.
Each transition requires the user to be of a certain type. Or from a user management point of view, have a certain role, or be member of a group.
If your workflow is fixed and is not subject to change, your method could be ok. But if the workflow is flexible or might be changed / adapted, you should go with something more flexible.
The type of setup you are talking about make me think of the Jira software (form Atlassian), where you define tickets, with status, workflows and users. Is it possible for you to use (i.e purchasse or OpenSource) a workflow management tool? It might be cheaper in the long run than building one.
Your model will potentially be expanded to include:
clients. Which client is the proposal for?
who is the sales representative or account manager who is responsible for auditing the workflow and moving it forward?
link to other systems: how does it link to purchasing, accounts receivable, ...
All this to day, this requires an in-depth analysis which is hard to do on a medium such as this (SO).
EDIT: 20181004
I added the following model following your comment. I decided to put the workflow(s) in the database:
Notes (tables in alphabetical order):
Employee
Each employee can be linked to n number of EmployeeRole via the Employee_has_EmployeeRole table.
Proposal
An Employee is linked as the Sales Officer, since he initiates a proposal.
A workflow is linked since many workflows could exist for different proposals.
Transition
Linked to State twice. The start state and the end state.
An EmployeeRole is linked, to identify which role an employee must have to perform this transition.
Enforcing that will be done by the application.
Workrlow_has_Transition
Links Transitions to Workflows.
The Employee who completed the transition is recorded here.
The date it was done is also kept here.
The OrderInWorkflow is just a number that allows you to order Workflow_has_Transition entries.
The application will have to make sure a Transition is not done before the others of lower order are done (i.e. DoneDate is null).
It will also validate that the Employee trying to complete it has the proper EmployeeRole.
Now, the employee group concept. You can say that a group are employees with the same EmployeeRole. Therefore, when a notification needs to be sent by your application, send it to all users with the required role for the Transition. This avoids you having to create an EmployeeGroup table, which links employees together.
Application scenarios:
- Start a Proposal
- Verify that the user trying to start a new one has the role "Sales Officer"
- Collect basic information.
- Link the Sales Officer to it (current user).
- Link a Workflow to it. Only propose the workflows which have at least 1 Workflow_has_Transition.
- Send a notification to the Employee(s) which have the EmployeeRole for the first Workflow_has_Transition for this new Workflow.
- These employees receive a notification.
- Progressing through the workflow
- An employee receives a notification about a Proposal and it's "todo" Transition.
- Employee views Proposal and Workflow (use the OrderInWorkflow to ORDER BY Transitions).
- Employee approves if he has the proper EmployeeRole, fill DoneBy_idEmployee and DoneDate.
While going through your application scenarios, you will find gaps or missing items.
Ex.1 do you want to record the rejection of a Transition? How would that be handled then? You send a notification to the employees with the role for that Transition to review it?
Ex.2 do you want to keep the complete history of the proposal? Ex. it Transition X is rejected twice, but approved the third time around.
There are many scenarios like this which will show the weaknesses of your model, which you fix as you complete this analysis. Now it is not perfect, I did not put a lot of time on it. But it is a starting point and illustrates my idea.
I would suggest you structure some where along this
ProposalBasicData {PBID,Title, ProposalDate,Scope,Objective}
ProposalState {PSID,Name}
UserType {UTID,Name}
User {UID,Name,UTID(Usertype UTID FK) }
Request{ RID, StartUID, StartDate ,PSID, IsActive }
RequestAction {AID,RID, RequesterUID, ReceiverUID, Date, Comments, IsCompleted }
as I think there could be multiple users of the same type, more over you would want to have comments on why it a RequestAction was rejected, A requester would make a requestAction to a receiver and if its completed it would show in the system make life easier when handling multiple requestActions of the same Request.
Hope this helps but i suggest you make a flow chart and look at what are all the possible use cases.

SalesForce: How can I link a custom object field to a value Account record

I am trying to find a solution of how to lookup a value on the Account Object and place it in a field on a record of a Custom Object.
Details below:
Objects
Accounts/ Organizations - This contains information on different projects supported by my origination. Key fields of note: Project Name(text) and Account Balance(text). There around 100 unique records in this object These field are manual led created.
Regrant Request - This object contains records that are generated via web form that the projects fill out to receive payment for expenses related to their project. Each Regrant Request record also contains the Project Name(text) Account Balance .
Desired Result:
When a new Regrant Request record is generated from the web form, it will take the value of the Project Name, match it with a record in the Accounts/Organization object. Once the link has been made, I would like to take the value of the Account Balance in the Accounts/ Organizations Object and copy to the Regrant Request record.
The problem that I am trying to solve is that in order a project to be paid the amount of money they request in the regrant request, they have to have enough funds. It would be great if I did not have to leave the regrant request record to find this value.
I know that I have to tie each regrant request record to an account id. That is stright forward but I am stuck on how to then get a value of field for said account id and then copy to a custom object.
any ideas would be extremely helpful!
I found out how to use zapier to do a search of the account object using the value of field inputted via the online form. So cool !

Any simple approaches for managing customer data change requests for global reference files?

For the first time, I am developing in an environment in which there is a central repository for a number of different industry standard reference data tables and many different customers who need to select records from these industry standard reference data tables to fill in foreign key information for their customer specific records.
Because these industry standard reference files are utilized by all customers, I want to reserve Create/Update/Delete access to these records for global product administrators. However, I would like to implement a (semi-)automated interface by which specific customers could request record additions, deletions or modifications to any of the industry standard reference files that are shared among all customers.
I know I need something like a "data change request" table specifying:
user id,
user request datetime,
request type (insert, modify, delete),
a user entered text explanation of the change request,
the user request's current status (pending, declined, completed),
admin resolution datetime,
admin id,
an admin entered text description of the resolution,
etc.
What I can't figure out is how to elegantly handle the fact that these data change requests could apply to dozens of different tables with differing table column definitions. I would like to give the customer users making these data change requests a convenient way to enter their proposed record additions/modifications directly into CRUD screens that look very much like the reference table CRUD screens they don't have write/delete permissions for (with an additional text explanation and perhaps request priority field). I would also like to give the global admins a tool that allows them to view all the outstanding data change requests for the users they oversee sorted by date requested or user/date requested. Upon selecting a data change request record off the list, the admin would be directed to another CRUD screen that would be populated with the fields the customer users requested for the new/modified industry standard reference table record along with customer's text explanation, the request status and the text resolution explanation field. At this point the admin could accept/edit/reject the requested change and if accepted the affected industry standard reference file would be automatically updated with the appropriate fields and the data change request record's status, text resolution explanation and resolution datetime would all also be appropriately updated.
However, I want to keep the actual production reference tables as simple as possible and free from these extraneous and typically null customer change request fields. I'd also like the data change request file to aggregate all data change requests across all the reference tables yet somehow "point to" the specific reference table and primary key in question for modification & deletion requests or the specific reference table and associated customer user entered field values in question for record creation requests.
Does anybody have any ideas of how to design something like this effectively? Is there a cleaner, simpler way I am missing?
Option 1
If preserving the base tables is important then I would create a "change details" table as a child to your change request table. I'm envisioning something like
ChangeID
TableName
TableKeyValue
FieldName
ProposedValue
Add/Change/Delete Indicator
So you'd have a row in this table for every proposed field change. The challenge in this scenario is maintaining the mapping of TableName and FieldName values to the actual tables and fields. If your database structure if fairly static then this may not be an issue.
Option 2
Add a ChangeID field to each of your base tables. When a change is proposed add a record to the base table with the ChangeID populated. So as an example if you have a Company table, for a single company you could have multiple records:
CompanyCode ChangeID CompanyName CompanyAddress
----------- -------- ----------- --------------
COMP1 My Company Boston <-- The "live" record
COMP1 1 New Name Boston <-- A proposed change
When the admin commits the change the existing live record is deleted or archived and the ChangeID value is removed from the proposed record making it the live record. It may be a little tricky to handle proposed deletions with this option. This option also has the potential for impacting performance of selecting live data for normal usage. However it does save you the hassle of maintaining a list of table names and field names somewhere in your code.
I'm sure others will have some opinions!

Resources