Steem Electron 데스크탑 앱 개발 - 글 포스팅 에러 수정하기 (1)
오픈소스 Ecency vision 을 포크하여 스팀잇에서 사용할 수 있도록 코드를 수정하고 있습니다.
그리고 작업하는 과정을 매일 기록하고 있습니다.
이전글
- 오픈소스 ecency-vision 포크해서 steemit electron 데스크탑 앱 개발하기 Start
- Steem Electron 데스크탑 앱 개발 - 로그인 첫번째
- Steem Electron 데스크탑 앱 개발 - 로그인 두번째
글을 작성하고 Publish 버튼을 누르면 에러가 발생하고 있어서 이 부분을 수정했습니다.
구글링 해보니 STEEM이 HIVE 포크되면서 Operation 스펙이 변경되었네요.
Affected operations:
comment_options
(!)
Old:percent_steem_dollars
New:percent_hbd
escrow_transfer
Old:steem_amount
,sbd_amount
New:hive_amount
,hbd_amount
escrow_release
Old:steem_amount
,sbd_amount
New:hive_amount
,hbd_amount
claim_reward_balance
Old:reward_steem
,reward_sbd
New:reward_hive
,reward_hbd
author_reward
(virtual operation)
Old:steem_payout
,sbd_payout
New:hive_payout
,hbd_payout
witness_update
Old:sbd_interest_rate
New:hbd_interest_rate
witness_set_properties
Old:sbd_interest_rate
,sbd_exchange_rate
New:hbd_interest_rate
,hbd_exchange_rate
변경된 스펙때문에 signedTransaction 객체 생성에서 에러가 발생합니다.
쉽게 해결하기 위해서 hive-tx 오픈소스를 포크하고 Steem에서 사용할 수 있게 코드를 수정했습니다.
그리고 수정한 패키지를 사용하여 sendOperations 함수를 재작성했습니다.
export const sendOperations = async (operations: Operation[], key: PrivateKey) => {
const props = await hiveClient.database.getDynamicGlobalProperties();
const ref_block_num = props.head_block_number & 0xffff;
const ref_block_prefix = Buffer.from(props.head_block_id, 'hex').readUInt32LE(4);
const expiration = new Date(new Date(props.time + 'Z').getTime() + hiveClient.broadcast.expireTime)
.toISOString()
.slice(0, -5);
const tx: Transaction = {
expiration,
extensions: [],
operations,
ref_block_num,
ref_block_prefix
};
const txr = new steemTx.Transaction(tx);
const privateKey = steemTx.PrivateKey.fromString(key.toString());
const signatures = txr.sign(privateKey).signatures;
const signedTransaction = { ...tx } as SignedTransaction;
signedTransaction.signatures = signatures;
const result = await hiveClient.broadcast.send(signedTransaction);
return result;
}
서명까지는 성공했습니다. 그런데 이번에는 broadcast send 하는 로직에서 에러가 발생합니다. 쉽지 않네요.
broadcast.send에는 @hiveio/dhive
패키지를 사용하고 있습니다. 여기서 에러가 나고 있네요.
다음번에는 @hiveio/dhive
패키지도 포크해서 코드를 수정해야 할 것 같습니다.
@anpigon transfered 1.0 KRWP to @krwp.burn. voting percent : 2.61%, voting power : 19.89%, steem power : 1945969.22, STU KRW : 1200.
@anpigon staking status : 68.5 KRWP
@anpigon limit for KRWP voting service : 0.068 KRWP (rate : 0.001)
What you sent : 1.0 KRWP
Refund balance : 0.931 KRWP [62844402 - 9cb8a0d02a78018f359b77ee512a04f1bd02a5ae]
[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.
@kr-dev.cu1님이 당신을 멘션하였습니다.
https://www.steemit.com/@kr-dev.cu1/20220329t130422094z